簡體   English   中英

ExpressionChangedAfterItHasBeenCheckedError 在 toastr 中解釋 Angular

[英]ExpressionChangedAfterItHasBeenCheckedError Explained in toastr Angular

我收到錯誤。 這似乎只有在加載時自動創建吐司時才會發生。 很可能是因為還沒有加載所有內容?

Error: ExpressionChangedAfterItHasBeenCheckedError: Expression has changed after it was checked. Previous value: 'undefined'. Current value: 'toast-success toast'. It seems like the view has been created after its parent and its children have been dirty checked. Has it been created in a change detection hook ?
at viewDebugError (core.es5.js:8420)
at expressionChangedAfterItHasBeenCheckedError (core.es5.js:8398)
at checkBindingNoChanges (core.es5.js:8562)
at checkNoChangesNodeInline (core.es5.js:12423)
at checkNoChangesNode (core.es5.js:12397)
at debugCheckNoChangesNode (core.es5.js:13174)
at debugCheckRenderNodeFn (core.es5.js:13114)
at Object.eval [as updateRenderer] (Toast_Host.html:1)
at Object.debugUpdateRenderer [as updateRenderer] (core.es5.js:13096)
at checkNoChangesView (core.es5.js:12219)
import { ToastrService } from 'ngx-toastr';
import { Component, OnInit } from '@angular/core';

@Component({
  selector: 'app-root',
  templateUrl: './app.component.html',
  styleUrls: ['./app.component.css']
})
export class AppComponent implements OnInit {
  title = 'app';

  constructor(private toastr: ToastrService) { }

  public ngOnInit(): void {
    this.toastr.success("testing", "testing");
  }
}

可能與https://github.com/angular/components/issues/5268有關,在setTimeout()中調用它。

ngOnInit() {
    setTimeout(() => this.toastr.success("testing", "testing"))
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM