1

i'm very-very noob at programming and intel xdk. i'm creating android application using Intel XDK and Ionic Framework, i want to use local storage to store my data. i've searched on internet and found some tutorial like using LokiJS and PouchDB, but when i tried it, it didn't working.

Then, i've found simple script local storage like this:

<h1>Welcome <span id="name"></span></h1>
<br>
<input id="input" placeholder="What is your name?">
<button onclick="setName()">Save</button>
<br>
<br>
<button onclick="getName()">Get the Name</button>

</div>
<script>
document.addEventListener("deviceready", function(){

document.getElementById("name").innerHTML = window.localStorage.getItem("name");

}, false);  

function setName(){     
window.localStorage.setItem("name", document.getElementById("input").value);
alert("Name added to localStorage");
}

function getName(){
alert(window.localStorage.getItem("name"));
}
</script>

it's working on my project, input->store->get , it's simple.

but now i want, if i input text, it will store to storage on some array, then i want to show the text on list view in intel xdk. Can i do that ?

husin.anti
  • 61
  • 1
  • 16

1 Answers1

0

Yes you can you can find in the documentation of the ionic ion-list is that the ion-list is just a simple angular directive you can use ng-repeat to loop through any array and populate this list .

if you have never used ng-repeat before this is a video tutorial i have recorded a while ago explaining it .

Also there has been a question answered here on stack overflow that explains how can you store full arrays in local storage and manipulate them .

The Tricky part is that local storage saves key value pairs so you will have to convert your array to a string and store it as a string literal then convert it again to an object when you intend to use it using the JSON.stringfy function

Community
  • 1
  • 1
Fady Sadek
  • 1,091
  • 1
  • 13
  • 22