docs(demos/localStorage): only display allowed keys

Related: https://github.com/driftyco/ionic-site/issues/453
This commit is contained in:
Drew Rygh
2016-04-16 17:32:05 -05:00
parent ba5624bc04
commit 617d36d42c
2 changed files with 22 additions and 3 deletions

View File

@ -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() {

View File

@ -58,6 +58,6 @@
<div padding>
<h5>Local Storage:</h5>
<pre>local: {{ localStorageDemo }}</pre>
<pre>local: {{ localStorageDemo | cleanLocalData }}</pre>
</div>
</ion-content>