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