I'm learning Angular (v6 to be specific), and trying to build a simple to do list.
I'm able to add items to an array and display in a list but cannot figure out how to delete specific items on click of that item.
Current code deletes the entire array on click. Here's my code:
app.component.html
<h1>To Do List</h1>
<label for="">What do you need to to?</label>
<input type="text" [(ngModel)]="listItem">
<br>
<button (click)="addToList()">Add</button>
<hr>
<ul>
<li *ngFor="let toDo of toDoList" (click)="removeFromList($event)">{{ toDo }}</li>
</ul>
app.component.ts
export class AppComponent {
title = 'to-do-list-app';
listItem = '';
toDoList = [];
addToList() {
this.toDoList.push(this.listItem);
}
removeFromList(addedItem) {
this.toDoList.splice(addedItem);
}