FormArray 调整数据位置

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"

  

posted @ 2022-09-07 15:24  飞尽堂前燕  阅读(8)  评论(0编辑  收藏  举报