angular2-todo
angular2-todo copied to clipboard
Adding another field
Hi,
Great work
I'm trying to add another field of text to fill out in the todo list.
However, it does not actually get added to the list (it is only seeing "newItem").
How do I add another field in the js?
This is the only modification I've made:
<header class="header">
<h1>todos</h1>
<input class="new-todo" placeholder="Vehicle" autofocus
[(ngModel)]="newItem" (keyup.enter)="addItem()">
<input class="new-todo" placeholder="Number of wheels" autofocus
[(ngModel)]="newItem1" (keyup.enter)="addItem()">
<button class="add" (click)="addItem()">Add</button>
</header>
i am not sure if I get this issue correctly but if you want to add a new field in HTML, shouldn't you be using a new variable to bind that field. You might want to create a new variable inside todolist.ts
similar to code as below
export default class TodoList {
newItem = 'test';
newItem1= 5;
// other stuff goes here
}
Once you have this new field, you can use its value inside addItem
function as below
addItem() {
this.store.dispatch(addItem(this.newItem + '-' + this.newItem1));
this.newItem = '';
this.newItem1 = '';
}