I am trying to set a default date for an input field of date data type.
This default date comes from a php file and is stored in a variable inside the .ts file: fecha_inicial
.
PHP function to get the date: date("d/m/Y");
.
fecha_inicial
varibale is correctly filled, as console.log('fecha_inicio',this.fecha_inicio)
shows a date like 17/09/2020. The variable is initialised in ngOnInit()
Then, the code I use for the input is the follwing:
<input type="date" data-date-format="DD/MM/YYYY" value="fecha_inicio" [(ngModel)]="fecha_inicio">
However, the input field is not being filled with the value of the variable... I think it might be a data type problem. Any ideas on how to solve it?
The code works if instead of type="date" i write type="text"
Use the Angular DatePipe
<input [ngModel]="fecha_inicio | date:'yyyy-MM-dd'" (ngModelChange)="fecha_inicio = $event" type="date" name="fecha_inicio"/>
Additional information here
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.