【问题标题】:Two way data binding in autocomplete component自动完成组件中的两种方式数据绑定
【发布时间】:2018-10-15 20:45:31
【问题描述】:

我在同一页面上有 Filter autocomplete i,e (车辆类型)Select with multiple selection i,e (车辆型号) 组件,如下所示图片:

这里我想用Select with multiple selection 组件执行双向数据绑定

如果我选择 Vehicle Type 作为 汽车 ,那么汽车 Vehicle Model 就像这样来的:

如果我选择 Vehicle Type 作为 Bikes ,那么自行车 Vehicle Model 就像这样:

这是stackblitz 链接。

【问题讨论】:

  • 您的问题到底是什么?看来您是在告诉我们您可以将Cars 更改为Bikes,复选框也会相应更改
  • 是的,我想根据bike/cars 中的更改更改列表(即复选框)。
  • 感谢您的回答。@chellappan

标签: angular angular-material angular6


【解决方案1】:

FormControl 有一个 valueChages 方法,它返回一个发出最新值的 observable。

试试这个

ngOnInit() {
    this.list = this.CarList;
    this.filteredOptions = this.myControl.valueChanges
      .pipe(
        startWith(''),
        map(value => this._filter(value))
      );
    this.myControl.valueChanges.subscribe((d) => {

      if (d === 'Cars') {
        this.list = this.CarList;
      } else {
        this.list = this.BikeList;
      }
    })

例如:https://stackblitz.com/edit/angular-4kxeab-glx4vg

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2019-03-09
    • 2016-02-27
    • 2019-03-26
    • 2017-05-20
    • 2011-11-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多