mirror of
https://github.com/ionic-team/ionic-framework.git
synced 2025-08-26 16:21:55 +08:00
Storage tesT
This commit is contained in:
42
ionic/components/app/test/storage/index.ts
Normal file
42
ionic/components/app/test/storage/index.ts
Normal file
@ -0,0 +1,42 @@
|
|||||||
|
import {Component, Control, ControlGroup} from 'angular2/angular2';
|
||||||
|
|
||||||
|
import {App, Storage, LocalStorage, SqlStorage} from 'ionic/ionic';
|
||||||
|
|
||||||
|
@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');
|
||||||
|
}
|
||||||
|
}
|
11
ionic/components/app/test/storage/main.html
Normal file
11
ionic/components/app/test/storage/main.html
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
<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>
|
Reference in New Issue
Block a user