0

Не могу отследить изменения в:

<input type="text" id="birthday" class="form-control" (ngModelChange)="onChange($event)" [(ngModel)]="user.birthday" ngControl="birthday">

при задания значения помощью

jQuery('#birthday').val('asdasd');
2
  • 2
    Странная идея менять значение поля ввода в ангуляре через jquery. 20 июн 2016 в 14:01
  • вызовите change событие вручную jQuery('#birthday').val('asdasd').change()
    – Grundy
    20 июн 2016 в 14:15

1 ответ 1

1

Форма:

<div class="form-group">
    <label for="birthday">Birthday:</label>
    <div class="input-group date">
        <span class="input-group-addon">
                <i class="fa fa-calendar"></i>
            </span>
        <input type="text" class="form-control" [(ngModel)]="user.birthday" ngControl="birthday">
    </div>
</div>

Контролер:

declare let jQuery: any;

export class EditUserComponent implements OnInit{
    private user = {};
}

ngOnInit() {
    let self = this;

    jQuery('.input-group.date').datepicker({
        todayBtn: "linked",
        keyboardNavigation: false,
        forceParse: false,
        calendarWeeks: true,
        autoclose: true,
        format: "yyyy-mm-dd"
    }).on('change', function(e) {
         let input = jQuery(this).children('input');
         self.user[input.attr( 'ngcontrol' )] = input.val();
    });
}
1
  • Суть задачи, подключения bootstrap datepicker, а не ng2-bootstrap datepicker
    – bderevyaga
    20 июн 2016 в 15:51

Ваш ответ

By clicking “Отправить ответ”, you agree to our terms of service and acknowledge you have read our privacy policy.

Всё ещё ищете ответ? Посмотрите другие вопросы с метками или задайте свой вопрос.