我这里有一个角的形状
https://stackblitz.com/edit/angular-form-array-duplicate-validation
我对此有两个问题。
ExpressionChangedAfterItHasBeenCheckedError:表达式已更改 在检查过之后。前值:“ng-有效:false”。当前 值:“ng-有效:true”
如何避免这两个错误?
我该如何避免这些问题。
发布于 2019-02-15 07:22:16
使用trackBy
trackBy函数将索引和当前项作为参数,并需要返回该项的唯一标识符。
component.html
<div formArrayName="credentials" *ngFor="let creds of form.controls.credentials?.value; let i = index;trackBy: cmpare;">
<ng-container [formGroupName]="i">
<input placeholder="Username" formControlName="username">
<input placeholder="Password" formControlName="password">
</ng-container>
</div>component.ts
cmpare(index) {
return index;
}分叉示例:https://stackblitz.com/edit/angular-form-array-duplicate-validation-8mojks
https://stackoverflow.com/questions/54703735
复制相似问题