mirror of
https://github.com/ionic-team/ionic-framework.git
synced 2025-08-20 12:29:55 +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 {App, Page, IonicApp, Config, Platform} from 'ionic-angular';
|
||||||
import {Storage, LocalStorage} 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({
|
@App({
|
||||||
template: '<ion-nav [root]="root"></ion-nav>'
|
template: '<ion-nav [root]="root"></ion-nav>',
|
||||||
|
pipes: [CleanLocalDataPipe]
|
||||||
})
|
})
|
||||||
class ApiDemoApp {
|
class ApiDemoApp {
|
||||||
constructor() {
|
constructor() {
|
||||||
@ -12,7 +30,8 @@ class ApiDemoApp {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Page({
|
@Page({
|
||||||
templateUrl: 'main.html'
|
templateUrl: 'main.html',
|
||||||
|
pipes: [CleanLocalDataPipe]
|
||||||
})
|
})
|
||||||
class MainPage {
|
class MainPage {
|
||||||
constructor() {
|
constructor() {
|
||||||
|
@ -58,6 +58,6 @@
|
|||||||
|
|
||||||
<div padding>
|
<div padding>
|
||||||
<h5>Local Storage:</h5>
|
<h5>Local Storage:</h5>
|
||||||
<pre>local: {{ localStorageDemo }}</pre>
|
<pre>local: {{ localStorageDemo | cleanLocalData }}</pre>
|
||||||
</div>
|
</div>
|
||||||
</ion-content>
|
</ion-content>
|
||||||
|
Reference in New Issue
Block a user