Ionic 2 And Json Data Addition
I am working with Ionic 2 Storage to persist form data. I save the data like this: this.storage.set(key, JSON.stringify(formData)); And I retrieve and attempt to update the data l
Solution 1:
what this error means is that, there are no records for that key at this moment. So, you would have to do a check like this :
this.getReport(key).then((report) => {
var objReport = [];//initialise empty Array
if(report){ //if there is a record in that key location
objReport = JSON.parse(report); //parse the record & overwrite objReport
}
objReport.push(data); //Now this push will happen regardless of report or not
this.storage.set(pk, JSON.stringify(objReport));
});
Post a Comment for "Ionic 2 And Json Data Addition"