以下是一个使用Angular 7从数组中删除特定值的示例代码:
values: string[] = ['Value 1', 'Value 2', 'Value 3'];
selectedValue: string;
splice
方法从数组中删除该值:removeValue() {
const index = this.values.indexOf(this.selectedValue);
if (index > -1) {
this.values.splice(index, 1);
}
}
removeValue
方法:
这样,当用户选择一个值并点击“Remove”按钮时,该值将从数组中删除。