gpt4 book ai didi

angular - ExpressionChangedAfterItHasBeenCheckedError 在 Angular 6 的 ngInit 中调用 toastr

转载 作者:行者123 更新时间:2023-12-01 01:21:49 26 4
gpt4 key购买 nike

注册后,用户将被重定向到登录页面,在 URL 中使用 ?welcome=1 参数,以便它可以显示欢迎词。

在登录组件中,我有:

ngOnInit() {
...
if (this.route.snapshot.queryParams['welcome']) {
this.toastr.success('Register Successful, please login');
}
}

我收到了他的信息:

Toast_Host.ngfactory.js? [sm]:1 ERROR Error: ExpressionChangedAfterItHasBeenCheckedError: Expression has changed after it was checked. Previous value: 'className: undefined'. Current value: 'className: 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.js:8445)
at expressionChangedAfterItHasBeenCheckedError (core.js:8433)
at checkBindingNoChanges (core.js:8535)
at checkNoChangesNodeInline (core.js:11401)
at checkNoChangesNode (core.js:11390)
at debugCheckNoChangesNode (core.js:11997)
at debugCheckRenderNodeFn (core.js:11951)
at Object.eval [as updateRenderer] (Toast_Host.ngfactory.js? [sm]:1)
at Object.debugUpdateRenderer [as updateRenderer] (core.js:11940)
at checkNoChangesView (core.js:11291)

我不明白,我没有做错任何事,也没有更改任何值,所以为什么会出现错误?

最佳答案

将 toastr 调用放入 ngAfterViewInit() 中的 setTimeout():

ngAfterViewInit() {
if (this.route.snapshot.queryParams['welcome']) {
setTimeout(() => {
this.toastr.success('Register Successful, please login');
}, 0);
}
}

关于angular - ExpressionChangedAfterItHasBeenCheckedError 在 Angular 6 的 ngInit 中调用 toastr,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50962765/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com