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.

subscribe for value changes on ng-model

See original GitHub issue

If I have an input:

<form #todo="form">
    <input type="text" ng-control="desc" [(ng-model)]="model.desc">
</form>

And I would like to subscribe to any changes to the model.desc, how would one do it?

If I’d be using the form builder, I’d be doing the following:

that.form = fb.group({
    desc: ['', Validators.required]
});
that.desc = that.form.controls.desc;

ObservableWrapper.subscribe(that.desc.valueChanges, function (value) {
    // do something here
})

And of course the markup would be a bit different as well:

<form #todo="form" [ng-form-model]="form">
    <input type="text" ng-control="desc">
</form>

But using the form builder and that.form.controls.desc makes the TS compiler complain that the desc property does not exist on a control.

Issue Analytics

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

github_iconTop GitHub Comments

2reactions
awerlangcommented, Mar 15, 2016

Create a directive which has an Observable input. Attach this directive to your form and pass todo.form.valueChanges to it.

0reactions
angular-automatic-lock-bot[bot]commented, Sep 8, 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

How do I detect change to ngModel on a select tag (Angular 2)?
As we can see, if we select a different value from the dropdown, our ngModel changes, and the interpolated expression in the view...
Read more >
ngModelChange and change events in Angular with examples
The value is updated by change event. As we used [ngModel] , on each input change ngModelChange will be called. And the UI...
Read more >
Difference between (change) and (ngModelChange) in Angular
Using (ngModelChange) essentially is listening to the input event, and setting the model if a user types, pastes or changes the input's value....
Read more >
NgModelChange & Change Event in Angular - TekTutorialsHub
NgModelChange is an Angular specific event, which we can use to listen for changes to the user input. It is the @Output property...
Read more >
NgModel - Angular
It accepts a domain model as an optional Input . If you have a one-way binding to ngModel with [] syntax, changing 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