J. Davidson
J. Davidson

Reputation: 3307

Deleting row of obect in a nested array Angular 2/4

I have a model that has array inside an array of object:

<div *ngFor="let n of shops?.locations let i=index;">
   <span>{{n.name}}</span>
   <button (click)="select(n, i)">select</button>
</div>
<popup>
<div *ngFor="let subloc of locationssub let j=index;">
   <span>{{subloc.id}}</span>
   <span><{{subloc.name}}</span>
   <button  (click)="delete(subloc, j)">del</button>
</div
</popup>

In my component I have:

 select(n, i){
    this.indexi=i;
    this.locationssub=n;
    this.popup.show();
 }

 delete(subloc, j){
    this.shops.locations[this.indexi].locationssub.splice(j,1);
 }

When I run this, it doesn't splice and remove the row.
How can i fix it?

Upvotes: 0

Views: 82

Answers (1)

MullisS
MullisS

Reputation: 278

Hello there are two possible reasons for this.

  1. Your code does not work (is the entry deleted from your array)
  2. Angular does not regonize the changes of your object, so you have to call changedetection after deleting: https://angular.io/api/core/ChangeDetectorRef

Upvotes: 1

Related Questions