docs(demos): local storage api demo

This commit is contained in:
Drew Rygh
2015-12-08 15:31:59 -06:00
parent ed5328939a
commit e522d2e0ff
3 changed files with 90 additions and 0 deletions

View File

@ -0,0 +1,2 @@
<ion-nav id="nav" [root]="rootPage" #content></ion-nav>
<ion-overlay></ion-overlay>

View 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 = '';
}
}

View 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>