首页 > 其他分享 >FormArray 调整数据位置

FormArray 调整数据位置

时间:2022-09-07 15:34:07浏览次数:64  
标签:index fromIdx toIdx 位置 FormArray trackBy beans 调整

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"

  

标签:index,fromIdx,toIdx,位置,FormArray,trackBy,beans,调整
From: https://www.cnblogs.com/MainActivity/p/16665612.html

相关文章