![](/img/trans.png)
[英]getting ExpressionChangedAfterItHasBeenCheckedError Angular 4
[英]Getting ExpressionChangedAfterItHasBeenCheckedError
在多个位置使用订阅行为对象以进行加载的组件时,遇到ExpressionChangedAfterItHasBeenCheckedError
。 将组件加载到一个组件中并尝试load
或destroy
另一个组件时,会发生错误。
@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))
关于它的更多信息
使用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.