【发布时间】:2019-11-21 12:16:49
【问题描述】:
在此stackblitz example 中考虑以下 Angular 选择。用户可以选择多个选项。有没有办法从其他地方取消选择这些选项?我说的是通过单击页面上其他位置的按钮来删除特定项目的勾号。
【问题讨论】:
-
这个答案可能会有所帮助:stackoverflow.com/a/57108032/2358409
标签: angular
在此stackblitz example 中考虑以下 Angular 选择。用户可以选择多个选项。有没有办法从其他地方取消选择这些选项?我说的是通过单击页面上其他位置的按钮来删除特定项目的勾号。
【问题讨论】:
标签: angular
尝试解决这个问题。
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
【讨论】: