要删除数组中的数据,可以使用Angular的ngModel指令结合数组的splice方法来实现。以下是一个示例:
在组件类中定义一个数组和一个删除数据的方法:
@Component({
  selector: 'app-example',
  template: `
    
      - 
        {{ item }}
        
      
`
})
export class ExampleComponent {
  items: string[] = ['item1', 'item2', 'item3'];
  removeItem(item: string) {
    const index = this.items.indexOf(item);
    if (index !== -1) {
      this.items.splice(index, 1);
    }
  }
}在模板中使用ngModel指令来绑定输入框的值,并在点击按钮时调用removeItem方法删除相应的数据。
注意:ngModel指令需要在FormsModule模块中导入才能使用。在模块类中添加如下导入语句:
import { FormsModule } from '@angular/forms';
@NgModule({
  imports: [
    FormsModule
  ],
  declarations: [
    ExampleComponent
  ],
})
export class ExampleModule { }
这样就可以在Angular中使用ngModel指令来实现从数组中删除数据的功能了。