Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Angular] Expression Changed After Checked Error #2258

Open
minhcu opened this issue Aug 11, 2024 · 0 comments
Open

[Angular] Expression Changed After Checked Error #2258

minhcu opened this issue Aug 11, 2024 · 0 comments

Comments

@minhcu
Copy link

minhcu commented Aug 11, 2024

https://github.com/tastejs/todomvc/blob/master/examples/angular/src/app/todo-item/todo-item.component.ts
https://github.com/tastejs/todomvc/blob/master/examples/angular/src/app/todo-item/todo-item.component.html

So I have copied this exact code and run it using Angular 18.
When the input is focused, the title property is changed, resulting in this error

handleFocus(e: Event) {
    this.title = this.todo.title;
  }

Expression Changed After Checked
https://angular.dev/errors/NG0100

It makes total sense that the title is changed in afterViewChecked hook creating this error. So is this a good practice?
Is there any better way to set up the title like when the todo is set or use onChanges hook?

@Input() set todo(data: Todo) {
    this._todo = data;
    this.title = this.todo.title;
}
@minhcu minhcu changed the title [Angular] Expression Changed After Checked [Angular] Expression Changed After Checked Error Aug 11, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant