diff --git a/demos/local-storage/index.ts b/demos/local-storage/index.ts
index 4d590f0443..dd634d50fe 100644
--- a/demos/local-storage/index.ts
+++ b/demos/local-storage/index.ts
@@ -3,26 +3,58 @@ import {Storage, LocalStorage} from 'ionic/ionic';
@App({
- templateUrl: 'main.html'
+ template: ''
})
class ApiDemoApp {
+ constructor() {
+ this.root = MainPage;
+ }
+}
+
+@Page({
+ templateUrl: 'main.html'
+})
+class MainPage {
constructor() {
this.local = new Storage(LocalStorage);
- this.myItem = {};
- this.delKey = '';
this.localStorageDemo = '{}';
window.localStorage.clear();
+
+ this.myItem = {
+ key: 'username',
+ value: 'admin'
+ };
+
+ this.keys = ['username', 'name', 'email', 'address'];
+ this.values = ['admin', 'Administrator', 'admin@administrator.com', '123 Admin St'];
+ this.addedKeys = [];
}
set() {
- this.local.set(this.myItem.key, this.myItem.value );
- this.localStorageDemo = JSON.stringify(window.localStorage, null, 2);
- this.myItem = {};
+ if (this.myItem.key) {
+ let added = false;
+
+ for (let i = 0; i < this.addedKeys.length; i++) {
+ if (this.addedKeys[i] == this.myItem.key) added = true;
+ }
+
+ if (added == false) {
+ console.log("Adding key", this.myItem.key);
+ this.addedKeys.push(this.myItem.key);
+ this.delKey = this.myItem.key;
+ this.local.set(this.myItem.key, this.myItem.value );
+ this.localStorageDemo = JSON.stringify(window.localStorage, null, 2);
+ }
+ }
}
remove() {
this.local.remove(this.delKey);
this.localStorageDemo = JSON.stringify(window.localStorage, null, 2);
- this.delKey = '';
+
+ let index = this.addedKeys.indexOf(this.delKey);
+ if (index > -1) {
+ this.addedKeys.splice(index, 1);
+ }
}
}
diff --git a/demos/local-storage/main.html b/demos/local-storage/main.html
index 594c573cd7..4362b94c0e 100644
--- a/demos/local-storage/main.html
+++ b/demos/local-storage/main.html
@@ -10,12 +10,20 @@
Key
-
+
+
+ {{ key }}
+
+
Value
-
+
+
+ {{ value }}
+
+
@@ -32,7 +40,12 @@
Key
-
+
+ Select a Key
+
+ {{ key }}
+
+
@@ -48,7 +61,3 @@
local: {{ localStorageDemo }}
-
-