【问题标题】:Unselect items in Angular Select在 Angular Select 中取消选择项目
【发布时间】:2019-11-21 12:16:49
【问题描述】:

在此stackblitz example 中考虑以下 Angular 选择。用户可以选择多个选项。有没有办法从其他地方取消选择这些选项?我说的是通过单击页面上其他位置的按钮来删除特定项目的勾号。

【问题讨论】:

标签: angular


【解决方案1】:

尝试解决这个问题。

select-custom-trigger-example.ts

  removeTomato() {
    const values = this.toppings.value;
    const index = values.indexOf('Tomato');
    if (index > -1) {
      values.splice(index, 1);
      this.toppings.setValue(values);
    }
  }

select-custom-trigger-example.html

<p (click)="removeTomato()">remove tomato</p>

已编辑:如果“番茄”被删除,您应该只 setValue

【讨论】:

    猜你喜欢
    • 2018-11-24
    • 2018-03-24
    • 2018-05-18
    • 2020-04-19
    • 2019-04-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多