2
我有一个formgroup命名输入窗体,有一个formarray的主题。我想使用动态创建的过滤列表来更改输入字段的值。如何在formArray中设置值
过滤功能工作正常:
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值。有人知道解决方案吗?
所有解释在https://stackoverflow.com/questions/41645677/change-formbuilder-array-items-in-nested-forms – Mihaly