angular8 - 检查后表达式已更改。以前的值:'mat-focused: false'。当前值:'mat-focused: true'。在角度 8?
问题描述
html代码:
ExpressionChangedAfterItHasBeenCheckedError:表达式在检查后已更改。以前的值:'mat-focused: false'。当前值:'mat-focused: true'。
当我单击包装材料输入时,它给出了这个错误。
<div formArrayName="packageArray" *ngFor="let item of packageArray.controls; let i = index;">
<div [formGroupName]="i" class="add-div" >
<p>Level {{i+1}} Pack</p>
<div class="d-flex justify-content-between">
<mat-form-field>
<input matInput type="text" (click)="addLevelPack(i)" placeholder="Package Material" formControlName="packMaterial" required>
在这一行,我得到了这个错误
</mat-form-field>
<mat-form-field>
<input matInput type="text" placeholder="UOM" formControlName="UOM" required>
</mat-form-field>
<mat-form-field>
<input matInput type="text" placeholder="Quantity" formControlName="Quantity" required>
</mat-form-field>
<mat-form-field>
<input matInput type="text" placeholder="Weight(kgs)" formControlName="weight" required>
</mat-form-field>
</div>
</div>
</div>
<div class="btn-custom" (click)="addPackage()">
<span mat-raised-button style="cursor:pointer">Add packaging +</span>
</div>
<p>Total packaging</p>
<div *ngFor="let item of packList; let i = index;">
<div class="file-name ">
<div class="d-flex">
<div class="p-2">
<div class="add-div d-flex justify-content-between">
<div> Level {{i+1}} Pack </div>
<div>{{item.packMaterial}}</div>
<div>{{item.UOM}}</div>
<div>{{item.Quantity}}</div>
<div>{{item.weight}}</div>
</div>
</div>
<div class="ml-auto p-2">(i need this arrangement also)
<mat-checkbox>WHD</mat-checkbox>
</div>
</div>
</div>
</div>
``````````````````````````````````````````````````````
component.ts(ExpressionChangedAfterItHasBeenCheckedError: Expression has changed after it was checked. Previous value: 'mat-focused: false'. Current value: 'mat-focused: true')
````````````````````````````````````````````````````````
ngOnInit() {
this.packageArray = this.formulationForm.get('packageArray') as FormArray;
this.addPackage();
}
addPackage(){
this.packageArray.push(this.createPackage());
}
createPackage():FormGroup{
return this.formBuilder.group({
packMaterial : new FormControl(null, Validators.required),
UOM : new FormControl(null, Validators.required),
Quantity: new FormControl(null, Validators.required),
weight: new FormControl(null, Validators.required)
});
}
addLevelPack(index){
this.dialog.open(SelectMaterialComponent, {data :{matList: this.packList , type: "Packaging"}, minWidth: '60vw', minHeight: '40vh'})
.afterClosed().subscribe( response => {
if(!!response) {
console.log(response);
this.formulationForm.get("packageArray").value.splice(-1, 1);
this.formulationForm.patchValue({packageArray : [
...this.formulationForm.get("packageArray").value,
{
packMaterial: response[0].title,
UOM: response[0].uom,
Quantity: 1,
weight: response[0].wt_in_kgs_per_unit
}
]});
this.packList = this.formulationForm.get("packageArray").value;
}
})
}
解决方案
尝试restoreFocus:false
像这样添加您的对话框配置:
this.dialog.open(SelectMaterialComponent, {
restoreFocus:false, // <-- Line to add
data :{matList: this.pack....
... }
})
推荐阅读
- c - 如何在没有指针的情况下存储变量的地址
- windows - 从 Linux VM 切换到 Windows VM docker toolbox windows 8.1
- apache-spark - 如何在一个微批量的 Spark 结构化流中设置批量大小
- arrays - 如何在Swift中删除除第一个/最后n个元素之外的所有数组项
- javascript - 未捕获的类型错误:无法读取 HTMLTableCellElement 处未定义的属性“样式”
- android - 如何使用 b4a 在 android 11(范围存储)中获得“所有文件访问”或“对文件夹的永久和完全访问”?
- javascript - 将 HTML 复制到剪贴板
- c - 用递归计算布尔表达式
- c# - 类库中的 C# 数据上下文
- cakephp - 按计数关联数据过滤查询 CakePHP 3