简体   繁体   English

使用异步 pipe 时的 ExpressionChangedAfterItHasBeenCheckedError

[英]ExpressionChangedAfterItHasBeenCheckedError when using async pipe

I get this error(ExpressionChangedAfterItHasBeenCheckedError) when I use async pipe!使用异步管道时出现此错误(ExpressionChangedAfterItHasBeenCheckedError)! The code is here .代码在这里 Where I'm doing wrong?我在哪里做错了?

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.

相关问题 使用共享组件时的 ExpressionChangedAfterItHasBeenCheckedError - ExpressionChangedAfterItHasBeenCheckedError when using shared component 使用滚动事件时的 ExpressionChangedAfterItHasBeenCheckedError - ExpressionChangedAfterItHasBeenCheckedError when using scroll event 使用 ReactiveForms 和 NgbModal 时的 ExpressionChangedAfterItHasBeenCheckedError - ExpressionChangedAfterItHasBeenCheckedError when using ReactiveForms and NgbModal 自定义 Pipe 在运行单元测试时导致 ExpressionChangedAfterItHasBeenCheckedError - Custom Pipe causes the ExpressionChangedAfterItHasBeenCheckedError when running a unit test 使用与ngFor的异步管道 - Using async pipe with ngFor 在 ngIf 中使用异步管道 - Using async pipe with ngIf 使用带有异步 pipe 的 forkJoin - Using forkJoin with async pipe Angular7 * ngIf在具有isLoading的应用程序组件中| 来自redux存储的异步管道抛出“ ExpressionChangedAfterItHaHasBeenCheckedError” - Angular7 *ngIf in app component with isLoading | async pipe from redux store throws “ExpressionChangedAfterItHasBeenCheckedError” 使用 ChildView 时如何修复 ExpressionChangedAfterItHasBeenCheckedError? - How to fix ExpressionChangedAfterItHasBeenCheckedError when using ChildView? 在窗体内使用Tab时出现ExpressionChangedAfterItHasBeenCheckedError - ExpressionChangedAfterItHasBeenCheckedError when using Tab inside a Form
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM