mirror of
https://github.com/ionic-team/ionic-framework.git
synced 2025-08-18 19:21:34 +08:00
feat(storage): new Local and WebSQL/SQLite key value storage service
This commit is contained in:
47
ionic/components/app/test/storage/index.ts
Normal file
47
ionic/components/app/test/storage/index.ts
Normal 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');
|
||||
}
|
||||
}
|
13
ionic/components/app/test/storage/main.html
Normal file
13
ionic/components/app/test/storage/main.html
Normal 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>
|
Reference in New Issue
Block a user