각도 추가 및 삭제 데이터

각도 추가 및 삭제 데이터

<div class="search_box">
    <input type="text" placeholder="请输入……"  [(ngModel)]="keyWord"><button (click)="searchBtn()" >搜索</button>
<hr>
    <div class="search_list" *ngFor="let item of historyList;let key=index">
        {{item}} <button (click)="delete(key)">X</button>
    </div>
</div>

export class ToDolistComponent implements OnInit {
  public keyWord: string;
  public historyList: any[] = [];
  constructor() { }

  ngOnInit() {
  }
  searchBtn() {
    if (this.historyList.indexOf(this.keyWord) == -1) {
      this.historyList.push(this.keyWord);
    }
    this.keyWord = '';
  }
  delete(key) {
    this.historyList.splice(key, 1);
  }
}

게시 24 개 원래 기사 · 원 찬양 4 · 조회수 4462

추천

출처blog.csdn.net/Amo__/article/details/101270693