get beans() {
return this.validateForm.get('beans') as FormArray;
}
change(fromIdx, toIdx){
const formGroup = this.beans.at(fromIdx);
this.beans.removeAt(fromIdx);
this.beans.insert(toIdx, formGroup);
}
trackByFn(index: any, item: any) {
return index;
}
同时需要在ng-for循环部分增加trackBy
*ngFor="let item of beans.controls; let i = index; trackBy:trackByFn"
原创文章,作者:ItWorker,如若转载,请注明出处:https://blog.ytso.com/tech/pnotes/288135.html