我有一个名为输入表单的表单组,有一个主题的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值。有人知道解决方案吗?
答案 0 :(得分:1)
this.yourdataobject.forEach(task => {
this.formcontrolname.push(
this.fb.group({
name: [task.name, Validators.required]
})
);
});