我遇到了一个错误:
ExpressionChangedAfterItHasBeenCheckedError: Expression has changed after it was checked. Previous value: 'true'. Current value: 'false'.
html
<div #visible >
<div [hidden]="toInt(visible.style.width)<19" >
</div>
</div>
.ts
toInt(x:string):number{
return parseInt(x);
}
通常的药物是在变化后明确运行变更检测。但是我没有更改.ts文件中的任何属性,所以我不知道要放在哪里
this.changeDetectorRef.detectChanges();
我该怎么办?
我在不同的情况下经历了痛苦。可能的修复是
- .ts
@ViewChild('visible') divElement: ElementRef;
中的访问#Visible 和.ts
ngAfterViewInit() { this._hideDiv= '<get the div length and do your condition>...'
}
最后在您的模板中
<div [hidden]="_hideDiv"> </div>