So… i am (obviously) pretty new to ionic / angular at all.
I got two views: a list of todolists; adding a new todolist to that list.
I can add a single new todolist object to the list. But if i want to add another one the list is gone. So the question is how i can save the objects in that list of todolists?
HTML to display the list of todolists: (todolist.html)
<ion-content padding>
<button end ion-button (click)="launchAddtodolistPage();">
Add todolist.
</button>
<ion-item *ngFor="let todo of todolistentries" (click)="launchTodoPage()">{{todo.title}}</ion-item>
</ion-list>
</ion-content>
(todolist.ts)
constructor(public navCtrl: NavController, public navParams: NavParams) {
this.addTodoListEntry();
}
addTodoListEntry() {
let e = new TodoListEntry();
e.title = this.navParams.get('title');
if (e.title != null) {
this.todolistentries.push(e);
}
}
launchAddtodolistPage() {
this.navCtrl.push(AddtodolistPage);
}
(addTodolist.html)
</ion-header>
<ion-content padding>
<ion-list>
<ion-item>
<ion-label color="primary" floating>Title</ion-label>
<ion-input [(ngModel)]="inputTitle"></ion-input>
</ion-item>
<ion-item>
<ion-textarea [(ngModel)]="inputDescription" color="primary" floating placeholder="Description">Description</ion-textarea>
</ion-item>
<ion-item>
<ion-label color="primary">Category</ion-label>
<ion-select [(ngModel)]="category" multiple="false">
<ion-option>Sports</ion-option>
<ion-option>University</ion-option>
<ion-option>Work</ion-option>
<ion-option>Private</ion-option>
</ion-select>
</ion-item>
<ion-item>
<ion-label color="primary">Priority</ion-label>
<ion-select [(ngModel)]="priority" multiple="false">
<ion-option>Low</ion-option>
<ion-option>Medium</ion-option>
<ion-option>High</ion-option>
</ion-select>
</ion-item>
</ion-list>
<button end ion-button (click)="newTodoEntry();">
Add todolist to list.
</button>
</ion-content>
(addTodolist.ts)
newTodoEntry() {
let e = new TodoListEntry();
e.title = this.inputTitle;
if (this.inputDescription != null) {
e.description = this.inputDescription;
}
this.navCtrl.push(TodolistsPage, {
title: e.title, description: e.description,
});
}
}
class TodoListEntry {
title: String;
description: String;
}