Angular 2: JQuery change not changing the binded variables value

时间:2018-03-13 15:11:09

标签: jquery typescript angular2-forms

I have a lot of input fields in a form. One of which is

<input type="text" name="client_openingbalance" 
[(ngModel)]="client.openingbalance" class="form-control">

Using jQuery I am modifying the value of this input field

$('.validateForm').on('keypress focusout paste','input',function(event){
        event.target.value = 100;
});

But unfortunately, this change is not reflected in client.openingbalance. Now, to achieve this I tried to add following lines of code.

$('.validateForm').on('keypress focusout paste','input',function(event){
        event.target.value = 100;
        $(this).trigger('click');
});

But is still not triggering ngModel. I cannot go and write code for every field.

Help would be appreciated.

1 个答案:

答案 0 :(得分:0)

试试这样:

$('.validateForm input').on('keypress focusout paste',function(event){
        event.target.value = 100;
});

该事件将触发input内的每个.validateForm

让我知道