Reputation: 95
I have project with array of notifications. I add them to template using *ngFor. How can I pass some data about current notification from template to delete it from array?
My project.ts
public notifications: Notification[] = [...someData];
clearOne() {
...should delete from array
}
My project.html
<div *ngFor="let n of notifications">
<div (click)="clearOne">{{ n }}</div>
</div>
Upvotes: 0
Views: 74
Reputation: 1627
<div *ngFor="let n of notifications">
<div (click)="clearOne(n)">{{ n }}</div>
</div>
In your component.ts
clearOne(notification) {
// Remove from array
let index = this.notifications.indexOf(notification);
this.notifications.splice(index, 1);
}
Upvotes: 2