It's due to some wierd bug related to using [value]
, instead go for [(ngModel)]
of template driven angular forms. The bug does not happen, when we use this directive and it does the same thing.
<input
type="text"
name="date{{i}}"
[(ngModel)]="row.planned_date"
*ngIf="req_d1.formatString"
[owlDateTime]="req_d1"
[owlDateTimeTrigger]="req_d1"
/>
Full Code:
import { Component, importProvidersFrom } from '@angular/core';
import { bootstrapApplication } from '@angular/platform-browser';
import { provideAnimations } from '@angular/platform-browser/animations';
import { CommonModule } from '@angular/common';
import {
OwlDateTimeModule,
OwlNativeDateTimeModule,
} from '@danielmoncada/angular-datetime-picker';
import { ReactiveFormsModule, FormsModule } from '@angular/forms';
@Component({
selector: 'app-root',
standalone: true,
imports: [
CommonModule,
OwlDateTimeModule,
OwlNativeDateTimeModule,
ReactiveFormsModule,
FormsModule,
],
template: `
<div *ngFor="let row of rows;trackBy: trackByFn; let i = index">
<div>{{ row.name }}</div>
<div>
<owl-date-time
#req_d1="owlDateTime"
[pickerType]="'calendar'"
></owl-date-time>
<input
type="text"
name="date{{i}}"
[(ngModel)]="row.planned_date"
*ngIf="req_d1.formatString"
[owlDateTime]="req_d1"
[owlDateTimeTrigger]="req_d1"
/>
</div>
<div>
`,
})
export class App {
rows = [
{ name: 1, planned_date: new Date() },
{ name: 2, planned_date: new Date() },
{ name: 3, planned_date: new Date() },
{ name: 4, planned_date: new Date() },
];
trackByFn(index: number) {
return index;
}
}
bootstrapApplication(App, {
providers: [
provideAnimations(),
importProvidersFrom([OwlDateTimeModule, OwlNativeDateTimeModule]),
],
});
updatePlannedDate