October 2017
Intermediate to advanced
280 pages
6h 50m
English
So far, so good! Now, let's implement the toggleCompletion method. This method accepts the index of the to-do item as an argument:
toggleCompletion(idx) {
let todo = this.todos[idx];
todo.completed = !todo.completed;
}
In toggleCompletion, we simply toggle the completed Boolean value associated with the current to-do item, which is specified by the index passed as an argument to the method.
Now, let's add a text input to add the new to-do items:
<p>
Add a new todo:
<input #newtodo type="text">
<button (click)="addTodo(newtodo.value); newtodo.value = ''">
Add
</button>
</p>
The input here defines a new variable called newtodo. Now, we can reference the input element using the newtodo identifier inside the template. ...
Read now
Unlock full access