[英]ExpressionChangedAfterItHasBeenCheckedError when using async pipe
I think the error is coming from {{users$|async|json}}
.我认为错误来自
{{users$|async|json}}
。 In layout service, it returns null and trying to display it causes an error.在布局服务中,它返回 null 并尝试显示它会导致错误。
I tested like that and I do not have any error.我这样测试过,没有任何错误。
<h1>Layout Component</h1>
<div>
<div *ngIf="layoutService.getSpinnerState|async">
<span>SPINING...
</span>
</div>
</div>
<p>StateSpinner: {{ layoutService.getSpinnerState|async }} </p>
ngOnInit() {
this.layoutService.withSpinner(this.profileService.getUser()).subscribe();
}
edit:编辑:
If I understand, the error, it is the change in your observable that makes it.如果我理解,错误是你的 observable 的变化造成的。
you can do something like that, when you call your layout service.当您调用布局服务时,您可以执行类似的操作。 What do you think?
你怎么看? It looks cleaner to me.
对我来说它看起来更干净。
withSpinner<T>(obs:Observable<T>){
this.setSpinnerState(true)
return obs.pipe(
delay(2000),
finalize(()=>this.setSpinnerState(false))
);
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.