So I made a simple todo list with Ionic and Angular. You can add and delete things to a list, which should be visible all the time. Everything works this far except for saving the data when closing the app.
Here is my home.page.ts:
export class HomePage {
name = '';
namelist = Array<string>();
constructor(public storage: Storage) {
let json = JSON.stringify(this.namelist);
localStorage.setItem('namelist', json);
var test = localStorage.getItem('namelist');
this.namelist = JSON.parse(test);
}
add() {
if (this.name.length > 0) {
let name = this.name;
this.namelist.push(name);
this.name = '';
}
}
delete(index) {
this.namelist.splice(index, 1);
}
namelist
is empty when u save it into the localstroage in the constructor, u can set a breakpoint to check