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"))
}
我遇到错误。这似乎只有在加载时自动创建吐司时才会发生。很可能是因为尚未加载所有内容?
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"))
}