我让我的HTTP拦截器在每次发出HTTP请求时打开加载栏:
intercept(req: HttpRequest<any>, next: HttpHandler): Observable<HttpEvent<any>> {
const dataStorageService = this.injector.get(DataStorageService);
dataStorageService.openProgressbar.next(true);
return next
.handle(req)
.do(evt => {
if (evt instanceof HttpResponse) {
dataStorageService.openProgressbar.next(false);
}
})
.catch(err => {
return Observable.throw(err);
});
}然后,在我的data-storage-service中,我有一个主题:
openProgressbar = new Subject<boolean>();我在我的应用组件中监听它,我把我的加载栏放在那里:
ngOnInit() {
this.dataStorageService.openProgressbar.subscribe(czyOtworzyc => {
this.alertMessageNavbarStatus = true;
});
}但ExpressionChangedAfterItHasBeenCheckedError正在显示。我正在寻找使用ngAfterContentChecked的解决方案,但它对我不起作用。有人能帮我吗?
发布于 2018-01-26 16:17:00
将ChangeDetectorRef注入到组件中
import { ChangeDetectorRef } from '@angular/core';
constructor(private _changeDetectorRef: ChangeDetectorRef) {}手动运行更改检测
ngOnInit() {
...
this._changeDetectorRef.detectChanges();
}https://stackoverflow.com/questions/48457666
复制相似问题