繁体   English   中英

获取ExpressionChangedAfterItHasBeenCheckedError

[英]Getting ExpressionChangedAfterItHasBeenCheckedError

在多个位置使用订阅行为对象以进行加载的组件时,遇到ExpressionChangedAfterItHasBeenCheckedError 将组件加载到一个组件中并尝试loaddestroy另一个组件时,会发生错误。

@Component({
template: 'common.component.html',
selector: 'app-common'
})

export CommonComponent implements OnInit{

constructor(service: MyService){}

ngOnInit(){
}

}

**common.component.html**

<div>
    <div *ngIf="service.isLoading$ | async">Loading...</div>
</div>


**component 1**

<div>
    <app-common></app-common>
</div>

component 2

<div>
    <app-common></app-common>
</div>


@Injectable()
export class MyService {
  public isLoading = new BehaviorSubject<any>(false);
  public isLoading$ = this.isLoading.asObservable();
}```
public isLoading$ = this.isLoading.asObservable().pipe(delay(0))

关于它的更多信息

https://blog.angular-university.io/angular-debugging/

使用ChangeDetectionStrategy.OnPush

import { ChangeDetectionStrategy } from '@angular/core';

@Component({template: 'common.component.html',
   selector: 'app-common',
   changeDetection: ChangeDetectionStrategy.OnPush
})

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM