Angular 4: NgModel not working. Does not set a value for the date field

Using Angular 4 I am trying to set a value for input of type "date", and I cannot do this. The structure of my field is as follows:

<input 
    type="date"
    class="form-control"                        
    ([ngModel])="edt_object.list_changedate" 
    (ngModelChange)="edt_object.list_changedate = $event"
    formControlName="list_changedate"
    name="list_changedate"
    id="list_changedate"
    style="width: 228px!important">

And the Typescript code I'm trying to set the value with is as follows:

this.edt_object.list_changedate = this.lista_selected.list_changedate

However, nothing happens. When I assign a value using jQuery (yes, using Angular and jQuery together), it works, BUT, when I try to check this field using Angular, the state of this field is "Invalid" because there is no value before Angular. What should I do?

+4
source share
2 answers

Edit

 ([ngModel])="edt_object.list_changedate" 
 (ngModelChange)="edt_object.list_changedate = $event"

to

 [ngModel]="edt_object.list_changedate" 
 (ngModelChange)="onChange($event)"

and implement onChange()how

onChange(event) {
    // emit event
}

[(ngModel)] - (ngModelChange) @Output ngModel. (ngModelChange), [ngModel]

+4

. this.ista_selected.list_changedate. "2016-10-13".

0

Source: https://habr.com/ru/post/1689983/


All Articles