[英]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.