angular2-todo icon indicating copy to clipboard operation
angular2-todo copied to clipboard

Adding another field

Open yarnball opened this issue 8 years ago • 1 comments

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>

yarnball avatar Aug 10 '16 04:08 yarnball

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 = '';
}

sumit-sinha avatar Sep 23 '16 14:09 sumit-sinha