在Angular 8中,当FormArray的索引数据未更新时,你可以尝试以下解决方法:
constructor(private formBuilder: FormBuilder) {
this.myForm = this.formBuilder.group({
myArray: this.formBuilder.array([])
});
}
// 移除索引为index的元素
this.myArray.removeAt(index);
// 插入一个新元素到索引为index的位置
this.myArray.insert(index, this.formBuilder.control(''));
确保在更新索引数据后,调用detectChanges方法来触发变更检测。
import { ChangeDetectorRef } from '@angular/core';
constructor(private cdr: ChangeDetectorRef) {}
// 在更新索引数据后调用detectChanges方法
this.cdr.detectChanges();
以上是一个简单的解决方法来解决Angular 8中FormArray索引数据未更新的问题。根据你的具体需求,你可能需要对代码进行适当的修改和调整。