【问题标题】:how to set value in formArray如何在formArray中设置值
【发布时间】:2017-06-13 14:45:55
【问题描述】:

我有一个名为输入表单的表单组,其中包含一个主题表单。我想使用动态创建的过滤列表更改输入字段的值。

过滤器功能正常:

filtertopic(idx: number) {
  const test = this.topics.value[idx].topic;
  if (test !== "") {
    this.onderdeel = "topics";
    this.queryselector = idx;
    this.filteredList = this.Topics.filter(function(el) {
      return el.toLowerCase().indexOf(test.toLowerCase()) >-1;
    }.bind(this));
     } else { this.filteredList = [];
    }
    }

但是改变输入字段值的函数handleBlur不起作用

handleBlur() {
    console.log(this.selectedIdx);
    if (this.selectedIdx > -1) {
      if (this.onderdeel =="topics") {
        this.topics.value[this.queryselector].topic.setValue(this.filteredList[this.selectedIdx]);
      } else {
        this.query = this.filteredList[this.selectedIdx];
      }
    }
    this.filteredList = [];
    this.selectedIdx = -1;
}

我认为这与

有关

this.topics.value[this.queryselector].topic.setValue(this.filteredList[this.selectedIdx]);

设置formcontrol值。有人知道解决办法吗?

【问题讨论】:

标签: forms angular


【解决方案1】:
 this.yourdataobject.forEach(task => {
      this.formcontrolname.push(
        this.fb.group({
          name: [task.name, Validators.required]
        })
      );
    });

【讨论】:

    猜你喜欢
    • 2021-07-10
    • 2018-12-03
    • 2022-01-04
    • 1970-01-01
    • 2019-02-19
    • 1970-01-01
    • 2021-09-24
    • 1970-01-01
    • 2017-04-14
    相关资源
    最近更新 更多