-
Notifications
You must be signed in to change notification settings - Fork 24.8k
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
Problem with property binding reevaluation with a template reference variable #22108
Comments
Seeing a Stack blitz reproduction would be great https://stackblitz.com/fork/angular-gitter |
Duplicate of #6618 ( |
@trotyl Thanks for the pointer! I understand why Angular maintainers may not want to change the current behavior given its potentially negative performance implication. But the current behavior of a template reference variable puts more strain on the developer's mind; it is one more exception that we need to remember and pay attention to. The current wording in the documentation (https://angular.io/guide/architecture) is clear and intuitive. "Angular processes all data bindings once per JavaScript event cycle", but the real behavior is, roughly, "All data binding is processed once per event cycle, unless the data binding contains only a template reference variable If the change of the current behavior leads to unbearably high overhead, there might be not much that the maintainers or users can do. We just have to take whatever is practically possible. But I hope that both sides of this option is carefully weighed by the community: the elegance and simplicity of the template syntax vs high-performance low-overhead implementation. |
@Toxicable Here it is: https://stackblitz.com/edit/angular-gitter-eafvrz?file=app%2Fapp.component.html The behavior of the first input box (which binds to the input event) is what I expected. The behavior of the second input box (with no input event binding) is rather unpredictable; the submit button stays disabled most of the time, but it gets enabled sometimes when I type something into the first input box. |
If no event listener defined, there won't be an event cycle (tick) in the JavaScript VM, it's technically true. |
I've formatted it a bit to make it easier to explain https://stackblitz.com/edit/angular-gitter-myueqn?file=app/app.component.ts
I believe this is the intended behavior of such a case. |
Hello, we reviewed this issue and determined that it doesn't fall into the bug report or feature request category. This issue tracker is not suitable for support requests, please repost your issue on StackOverflow using tag If you are wondering why we don't resolve support issues via the issue tracker, please check out this explanation. |
This issue has been automatically locked due to inactivity. Read more about our automatic conversation locking policy. This action has been performed automatically by a bot. |
I'm submitting a...
Current behavior
Expected behavior
In a template I include the following HTML code:
<input type ="text" #query><input type ="submit" [disabled]="!query.value">
I expect the the submit button is disabled by default, but when I type something into the input box, it gets enabled since the property binding will be reevaluated in every event cycle. But that is not what is happening. The button stays disabled.
If I change the above code to the following,
<input type ="text" (input)="0" #query><input type ="submit" [disabled]="!query.value">
and add an explicit event binding (which has nothing to do with the template variable itself), it behaves as intended. I think there is an overaggressive optimization is going on, which is not in compliance with what is stated in this page: https://angular.io/guide/architecture
"Angular processes all data bindings once per JavaScript event cycle, from the root of the application component tree through all child components."
Minimal reproduction of the problem with instructions
What is the motivation / use case for changing the behavior?
Environment
The text was updated successfully, but these errors were encountered: