0

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>

1 Answer 1

2
<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);
}
Sign up to request clarification or add additional context in comments.

1 Comment

really, the problem was with clearOne() method, but not with passing object. It works now!

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.