I am working on prototyping out an application where I would like to use SqlStorage. Currently, I am working through the get/set functionality which seems really simple and clean. The issue I am running into is that the if the array contains objects, I am receiving the following error:
EXCEPTION: Cannot find a differ supporting object '[object Object]'
Here is my code:
Record provider:
import {Injectable} from 'angular2/core';
import {Http} from 'angular2/http';
import {Storage, SqlStorage} from 'ionic/ionic';
@Injectable()
export class Record {
constructor() {
this.storage = new Storage(SqlStorage);
this.storage.set('test', JSON.stringify([
{
prop1: "test",
prop2: "testc",
prop3: 'test',
total: "8",
prop4: "test",
prop5: "test",
prop6: "test",
prop7: true
}
]));
this.data = null;
}
load() {
if (this.data) {
// already loaded data
return Promise.resolve(this.data);
}
// don't have the data yet
return new Promise(resolve => {
// We're using Angular Http provider to request the data,
// then on the response it'll map the JSON data to a parsed JS object.
// Next we process the data and resolve the promise with the new data.
resolve(
this.storage.get('test').then(function (result) {
return JSON.parse(result);
}));
});
}
}
Page:
import {Page, NavController} from 'ionic/ionic';
import {Record} from 'providers/records/record';
@Page({
templateUrl: 'build/pages/testpage/testpage.html',
providers:[Record]
})
export class Testpage {
constructor(nav:NavController, rec: Record) {
this.nav = nav;
this.records = rec.load().then(function(results) {
this.records;
});
}
method1(record) {
console.log(record);
}
method2(record) {
console.log(record);
}
}
Even if the code errors out with the above error, I still get the data array printed to the console.log from the promise resolve in the provider.
Thoughts?