A
A
Anton Tarara2017-09-28 10:06:34
Angular
Anton Tarara, 2017-09-28 10:06:34

How to change ngModel if we change the input not in the context of angular 2?

There is a component, in the layout there is an input tied through [(ngModel)] to the field of the component class. Let's say we change the value of the input through a third-party script. For example JQuery through $('input').val("value"), then in angular the value of the model does not change. How to rebind or something else to pick up this change?

Answer the question

In order to leave comments, you need to log in

3 answer(s)
D
denismaster, 2017-09-28
@denismaster

you may also need to trigger the Input event on the element.
Here you can see the implementation features of ngModel for the standard input

F
Fedor Sazonov, 2017-09-28
@Revenant20

You can try this one . And so the third-party script also has an event, can it bind through it?

K
Klein Maximus, 2017-09-28
@kleinmaximus

ngModel is not a reference to the same memory area, but "syntactic sugar".
When the input value changes, an event occurs, which allows you to use two-way binding.
https://metanit.com/web/angular2/5.2.php

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question