Destroy the component yourself - angular2

I have a component ( main-cmp ) with rows from a database. For strings, I create another component, for example. row-cmp

main-cmp requested data from the database and analyzed it as

 <row-cmp *ngFor="let row of data" [id]="row.id" [name]="row.name" [value]="row.value"> </row-cmp> 

In row-cmp I declare a delete() function that calls an HTTP request for my backend. Now that the response from the request is true, I want to destroy row-cmp for the selected row. Is it possible?

+6
source share
1 answer

This is not supported. I would suggest adding an eventemitter

 @Output() delete:EventEmitter = new EventEmitter(); 

and then add an event handler that removes the item from the data array

 <row-cmp *ngFor="let row of data;let i=index" (delete)="data.splice(i,1)" [id]="row.id" [name]="row.name" [value]="row.value"> </row-cmp> 
+8
source

Source: https://habr.com/ru/post/1011471/


All Articles