With the following code I am able HTTP get a remote JSON use it in a ng*For and save it as a key value pair in sqlite successfully.
What I am trying accomplish is when I have a connection error i.e no cellular connection, is fall back on storage.get to JSON.parse the data in the sqlite db and use it for the ng*For. I have done this with Ionic 1 but a little unsure how I would accomplish this with ionic 2
import {Page, Storage, SqlStorage} from 'ionic/ionic';
import {Http} from 'angular2/http';
import 'rxjs/add/operator/map';
@Page ({
templateUrl: 'build/pages/remote/remote.html',
})
export class Remote {
constructor(http: Http) {
this.http = http;
this.corptest = null;
this.storage = new Storage(SqlStorage);
this.http.get('http://www.something/test.json')
//.timeout(1000)
.map(res => res.json())
.subscribe
(data => {
this.corptest = data;
this.storage.set ("corptest", JSON.stringify(data));
},
err => {
//Error is here
this.storage.get ("corptest", JSON.parse(data));
console.log("screwed up still!")
}
});
}