簡體   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