Binding with [(ngModel)] an Input of type Date not showing the date

Discussão em 'Angular' iniciado por Mauro Ghiglia, Fevereiro 7, 2025.

  1. I'm trying to display (Angular 15), in a form, a preset date that I created in the component this way:

    defaultOpening: Opening = new Opening(1, new Date(), new Date());
    ngOnInit() {
    this.HotelModel.openings.push(this.defaultOpening);
    }


    The field is showing correctly in the ngFor loop:

    <tr *ngFor="let opening of HotelModel.openings">
    <td>{{ opening.start | date : 'yyyy-MM-dd' }}</td>
    <td>{{ opening.end | date : 'yyyy-MM-dd' }}</td>
    </tr>


    [​IMG]

    But show as empty date fields in this loop:

    <tr *ngFor="let opening of HotelModel.openings; let i = index">
    <td><input [(ngModel)]="opening.start" name="startMonth{{i}}" type="date"></td>
    <td><input [(ngModel)]="opening.end" name="startDay{{i}}" type="date"></td>
    </tr>


    Like this: [​IMG]

    Is there a way to show it?

    Continue reading...

Compartilhe esta Página