question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Error: ExpressionChangedAfterItHasBeenCheckedError: Expression has changed after it was checked

See original GitHub issue

Receiving the following error:

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)

This is caused by the following code:

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");
  }
}

This only seems to happen when a toast is created automatically on load. Most likely because not everything is loaded yet?

Doesn’t happen when everything is loaded (ex: on button press)

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:5
  • Comments:12 (3 by maintainers)

github_iconTop GitHub Comments

42reactions
scttcpercommented, Aug 11, 2017

call it inside a setTimeout

ngOnInit() {
    setTimeout(() => this.toastr.success('sup'))
}
0reactions
itumeleng-modisecommented, Oct 10, 2018

I am aware that this issue was closed without a solution or a proper solution. I believe sharing this could be helpful. It seems like the issue has something to do with angular life cycle hooks. I am yet to find time to learn about the details. For my case I moved this.toastrService.success(this.message); from ngOnInit() to constructor() as recommended here: https://stackoverflow.com/questions/43375532/expressionchangedafterithasbeencheckederror-explained

Read more comments on GitHub >

github_iconTop Results From Across the Web

NG0100: Expression has changed after it was checked - Angular
Angular throws an ExpressionChangedAfterItHasBeenCheckedError when an expression value has been changed after change detection has completed.
Read more >
Expression ___ has changed after it was checked
In my case I was opening a modal. After open the modal it was showing the message "Expression ___ has changed after it...
Read more >
Angular Debugging "Expression has changed": Explanation ...
Learn a complete explanation about ExpressionChangedAfterItHasBeenCheckedError: why it occurs, how to troubleshoot it and how to fix it.
Read more >
Fixing "Expression has changed after it was checked" in Angular
AppComponent.html:1 ERROR Error: ExpressionChangedAfterItHasBeenCheckedError: Expression has changed after it was checked. Previous value: 'ngIf: true'.
Read more >
Expression Has Changed After It Was Checked — Angular ...
Error : ExpressionChangedAfterItHasBeenCheckedError: Expression has changed after it was checked. Previous value: 'A message for the child component'.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found