How to store new record in ionic storage?


#1

Friends,

I have a small app to store bike details . I can add Bike details(Bike name, Model, Register No) . But when I add new bike it overwrite the existing one . How it can handle ?

Please give a sample code to handle the same situation

When I try this code

    var items = this.storage.get('bike');
    items.push(this.bike);
    this.storage.set('bike',items);

I got error on apk creation as

Error: Failed to transpile program
    at new BuildError (/home/user/newapp/node_modules/@ionic/app-scripts/dist/util/errors.js:16:28)
    at /home/user/newapp/node_modules/@ionic/app-scripts/dist/transpile.js:159:20
    at new Promise (<anonymous>)
    at transpileWorker (/home/user/newapp/node_modules/@ionic/app-scripts/dist/transpile.js:107:12)
    at Object.transpile (/home/user/newapp/node_modules/@ionic/app-scripts/dist/transpile.js:64:12)
    at /home/user/newapp/node_modules/@ionic/app-scripts/dist/build.js:109:82
    at <anonymous>

Please advise

Thanks

Anes


#2

use sqlite


#3

storage.get returns a Promise, not a value. See the usage example on https://ionicframework.com/docs/storage/