这是在我的 html 文件中:
<div id="my-div" [ngClass]="hasSetting ? 'my-container' : 'opacity-div my-container'">
<dx-load-panel
#loadPanel
[(visible)]="!hasSetting" >
</dx-load-panel>
</div>
这是我的组件:
export class TurnoverWidgetComponent {
departments: DropdownOption[] = [];
hasSetting: boolean;
constructor(
private myService: MyService
) {
forkJoin(
this.myService.hasSetting(),
this.myService.getDepartments()
).subscribe(
([hasSetting, departments]) => {
this.hasSetting = hasSetting;
this.departments = departments.map(item => {
return {
id: item.id,
name: item.name
}
});
}
);
}
}
我收到错误错误:检查后表达式已更改-在构造函数中,从真到假,反之亦然。根据我的研究,此错误发生在组件初始化后发生的事件中,但是我没有此类事件,我的更改发生在构造函数中。我试着把它放在 oninit 事件中,同样的事情发生了。