feat(storage): new Local and WebSQL/SQLite key value storage service

This commit is contained in:
Max Lynch
2015-09-03 23:16:50 -05:00
parent c32eedde76
commit ee2486b76a
6 changed files with 259 additions and 0 deletions

View File

@ -0,0 +1,47 @@
import {Component} from 'angular2/angular2';
import {Control, ControlGroup} from 'angular2/forms';
import {App, Http, Storage, LocalStorage, SQLStorage} from 'ionic/ionic';
let testUrl = 'https://ionic-api-tester.herokuapp.com/json';
let testUrl404 = 'https://ionic-api-tester.herokuapp.com/404';
@App({
templateUrl: 'main.html'
})
class IonicApp {
constructor() {
this.local = new Storage(LocalStorage);
this.sql = new Storage(SQLStorage);
}
getLocal() {
this.local.get('name').then(value => {
alert('Your name is: ' + value);
});
}
setLocal() {
let name = prompt('Your name?');
this.local.set('name', name);
}
removeLocal() {
this.local.remove('name');
}
getSql() {
this.sql.get('name').then(value => {
alert('Your name is: ' + value);
}, (errResult) => {
console.error('Unable to get item from SQL db:', errResult);
});
}
setSql() {
let name = prompt('Your name?');
this.sql.set('name', name);
}
removeSql() {
this.sql.remove('name');
}
}

View File

@ -0,0 +1,13 @@
<ion-view>
<ion-content padding>
<h2>Local Storage</h2>
<button primary (click)="getLocal()">Get</button>
<button primary (click)="setLocal()">Set</button>
<button primary (click)="removeLocal()">Remove</button>
<h2>SQL Storage</h2>
<button primary (click)="getSql()">Get</button>
<button primary (click)="setSql()">Set</button>
<button primary (click)="removeSql()">Remove</button>
</ion-content>
</ion-view>