mirror of
https://github.com/ionic-team/ionic-framework.git
synced 2025-08-18 03:00:58 +08:00
docs(demos): local storage api demo
This commit is contained in:
2
demos/local-storage/app.html
Normal file
2
demos/local-storage/app.html
Normal file
@ -0,0 +1,2 @@
|
||||
<ion-nav id="nav" [root]="rootPage" #content></ion-nav>
|
||||
<ion-overlay></ion-overlay>
|
38
demos/local-storage/index.ts
Normal file
38
demos/local-storage/index.ts
Normal file
@ -0,0 +1,38 @@
|
||||
import {App, Page, IonicApp, Config, Platform} from 'ionic/ionic';
|
||||
import {Storage, LocalStorage} from 'ionic/ionic';
|
||||
|
||||
|
||||
@App({
|
||||
templateUrl: 'app.html'
|
||||
})
|
||||
class ApiDemoApp {
|
||||
|
||||
constructor() {
|
||||
this.rootPage = InitialPage;
|
||||
}
|
||||
}
|
||||
|
||||
@Page({
|
||||
templateUrl: 'main.html'
|
||||
})
|
||||
export class InitialPage {
|
||||
constructor() {
|
||||
this.local = new Storage(LocalStorage);
|
||||
this.myItem = {};
|
||||
this.delKey = '';
|
||||
this.localStorageDemo = '{}';
|
||||
window.localStorage.clear();
|
||||
}
|
||||
|
||||
set() {
|
||||
this.local.set(this.myItem.key, this.myItem.value );
|
||||
this.localStorageDemo = JSON.stringify(window.localStorage, null, 2);
|
||||
this.myItem = {};
|
||||
}
|
||||
|
||||
remove() {
|
||||
this.local.remove(this.delKey);
|
||||
this.localStorageDemo = JSON.stringify(window.localStorage, null, 2);
|
||||
this.delKey = '';
|
||||
}
|
||||
}
|
50
demos/local-storage/main.html
Normal file
50
demos/local-storage/main.html
Normal file
@ -0,0 +1,50 @@
|
||||
<ion-navbar *navbar>
|
||||
<ion-title>Local Storage</ion-title>
|
||||
</ion-navbar>
|
||||
|
||||
<ion-content padding>
|
||||
|
||||
<ion-row>
|
||||
<ion-col width-33>
|
||||
<ion-input>
|
||||
<input type="text" placeholder="Key" [(ng-model)]="myItem.key">
|
||||
</ion-input>
|
||||
</ion-col>
|
||||
|
||||
<ion-col width-33>
|
||||
<ion-input>
|
||||
<input type="text" placeholder="Value" [(ng-model)]="myItem.value">
|
||||
</ion-input>
|
||||
</ion-col>
|
||||
|
||||
<ion-col width-34>
|
||||
<button full secondary (click)="set()">
|
||||
<icon add></icon>
|
||||
set()
|
||||
</button>
|
||||
</ion-col>
|
||||
</ion-row>
|
||||
|
||||
<ion-row>
|
||||
|
||||
<ion-col width-33>
|
||||
<ion-input>
|
||||
<input type="text" placeholder="Key" [(ng-model)]="delKey">
|
||||
</ion-input>
|
||||
</ion-col>
|
||||
|
||||
<ion-col width-34 offset-33>
|
||||
<button full danger (click)="remove()">
|
||||
<icon remove></icon>
|
||||
remove()
|
||||
</button>
|
||||
</ion-col>
|
||||
</ion-row>
|
||||
|
||||
<ion-row>
|
||||
<b>Local Storage:</b>
|
||||
<ion-col>
|
||||
{{localStorageDemo}}
|
||||
</ion-col>
|
||||
</ion-row>
|
||||
<ion-content>
|
Reference in New Issue
Block a user