I'm new to angular, but I need to assign a date to a html input of type date when loading the page.
I noticed that if you change the input type from date to text, the value is assigned to the input, but leave as date the value is not assigned.
Someone would know where I'm going wrong.
Follow me code.
HTML
<input class="form-control"
type="date"
maxlength="10"
placeholder="dd/mm/yyyy"
[(ngModel)]="carFilter.dataInicial"
(ngModelChange)="onDateChangeFim($event)"
min="{{auxFimMinDate}}"
max="{{auxFimMaxDate}}">
Component Example
export class CarComponent implements AfterViewInit, OnInit {
carFilter : CarModel;
auxInMaxDate: Date = new Date("2099-12-30");
auxFimMinDate: Date = new Date("1900-01-01");
ngOnInit(): void {
this.carFilter = new CarModel();
const data = new Date();
this.carFilter.dataInicial = data;
}
}
Model Example
export class CarModel {
offSet : number;
dataInicial : Date;
dataFinal : Date;
constructor(
offSet:number,
dataInicial : Date,
dataFinal : Date
){
this.offSet = offSet;
this.dataInicial = dataInicial;
this.dataFinal = dataFinal;
}
}
Image input
Console Google Chrome

