删除按钮并列出值

时间:2019-04-10 11:00:44

标签: angular

我有一个包含值和按钮的列表。我试图在删除值时删除按钮。我的代码将对此进行更好的解释。目前这还没有发生。该值已删除,但删除按钮仍然保留。每次将值添加到列表时,也会添加一个删除按钮。删除值后,我也无法删除删除按钮。

  <div *ngFor="let location of basics.locations; let index = index; trackBy: customTrackBy">
  <div  class="ui-g-12 ui-md-12 input-container">
    <label for="location1">Location {{index + 1}}*</label>
    <input [(ngModel)]="location.name" type="text" size="50" placeholder="Location" required>
    <span *checkIcon="location.name"></span>
  </div>

  <div class="ui-g-12 ui-md-12">
    <button type="button" (click)="deleteLocation(index)" class="add-location-btn btn btn-primary"> DELETE </button>
  </div>
  </div>

  deleteLocation(index) {
    this.basics.locations.splice(index, 1);
  }

0 个答案:

没有答案