mirror of
https://github.com/ionic-team/ionic-framework.git
synced 2025-08-20 04:14:21 +08:00
docs(demos/localStorage): only display allowed keys
Related: https://github.com/driftyco/ionic-site/issues/453
This commit is contained in:
@ -1,9 +1,27 @@
|
||||
import {App, Page, IonicApp, Config, Platform} from 'ionic-angular';
|
||||
import {Storage, LocalStorage} from 'ionic-angular';
|
||||
import {Pipe, PipeTransform, Injectable} from 'angular2/core'
|
||||
|
||||
|
||||
@Pipe({name: 'cleanLocalData'})
|
||||
@Injectable()
|
||||
class CleanLocalDataPipe implements PipeTransform {
|
||||
transform(obj:any) : any {
|
||||
this.validKeys = ['username', 'name', 'email', 'address'];
|
||||
this.output = {};
|
||||
this.data = JSON.parse(obj);
|
||||
for (var i = 0; i < Object.keys(this.data).length; i++) {
|
||||
if (this.validKeys.indexOf( Object.keys(this.data)[i] ) > -1) {
|
||||
this.output[Object.keys(this.data)[i]] = this.data[Object.keys(this.data)[i]];
|
||||
}
|
||||
}
|
||||
return JSON.stringify(this.output, null, 2);
|
||||
}
|
||||
}
|
||||
|
||||
@App({
|
||||
template: '<ion-nav [root]="root"></ion-nav>'
|
||||
template: '<ion-nav [root]="root"></ion-nav>',
|
||||
pipes: [CleanLocalDataPipe]
|
||||
})
|
||||
class ApiDemoApp {
|
||||
constructor() {
|
||||
@ -12,7 +30,8 @@ class ApiDemoApp {
|
||||
}
|
||||
|
||||
@Page({
|
||||
templateUrl: 'main.html'
|
||||
templateUrl: 'main.html',
|
||||
pipes: [CleanLocalDataPipe]
|
||||
})
|
||||
class MainPage {
|
||||
constructor() {
|
||||
|
@ -58,6 +58,6 @@
|
||||
|
||||
<div padding>
|
||||
<h5>Local Storage:</h5>
|
||||
<pre>local: {{ localStorageDemo }}</pre>
|
||||
<pre>local: {{ localStorageDemo | cleanLocalData }}</pre>
|
||||
</div>
|
||||
</ion-content>
|
||||
|
Reference in New Issue
Block a user