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.

Template <input> local variable value not updated as user types

See original GitHub issue

To illustrate this problem, I setup the Angular 2 quickstart example for Dart named hello_world, and changed the template to be:

<div>
  <h1>Hello {{ nm.value }}</h1>
  <input #nm value="Al" type="text" >
  <a href="#" (click)="0">Do nothing</a>
</div>

When I launch the app I see “Hello Al” as expected. If I type new input text in the browser, the <h1> greeting DOES NOT update. But if I click on the “Do nothing” link (which invokes a noop event handler), then the <h1> greeting updates to match the input text value.

Shouldn’t nm.value in the <h1> greeting update as I type?

Now, by extension of the above, if I add a noop event handler (input)="0" to the <input> element, then the update to the input text gets propagated as I type. Is this the way to go? (Note that in this example I am deliberately trying to avoid using a model field as an intermediary to transport input value.)

I’m thinking that this might be a consequence of the new Angular 2 digest phase (vs. digest cycle), but I wanted to double check that this isn’t a bug. E.g. pkozlowski-opensource/ng2-play uses a timer to delay the change of a model field, and the change is detected. Why can’t nm be considered a “template local” model field and hence have any updates picked up automatically?

Btw, note that I have tested this with the current head of angular (i.e., 1872b03fb8513614eca0111d92f3316ee1f9672e).

Issue Analytics

  • State:closed
  • Created 9 years ago
  • Comments:8 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
mheverycommented, Mar 26, 2015

This works as intended. You must have a listener such as <input (keyup)> to trigger change detection.

We will document this.

0reactions
angular-automatic-lock-bot[bot]commented, Sep 6, 2019

This issue has been automatically locked due to inactivity. Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Component template variable not updating when service ...
When you need the up-to-date value in component, use only the observable and do not use the boolean flag from the service directly....
Read more >
Angular - Not Detecting Change, Updating Variable When ...
In the Angular app, we need to make changes in local variables which are getting used and defined as global. These variable or...
Read more >
without changing the rule input values how to update ...
Hi,. i am using multidrop down field , i want to update my new values into local variable first then i want to...
Read more >
Understanding template variables
Use template variables to perform tasks such as respond to user input or finely tune your application's forms. A template variable can refer...
Read more >
Javascript variable to a Local Variable not updating the first ...
Create a local variable that binds to a hidden input; Create a JS variable and use the hidden input Id to assign the...
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