我需要在ngFor中创建matDatepickers。我使用如下
<div *ngFor="let interim_payment_date of interim_payment_multi; let i = index" [attr.data-index]="i">
<mat-form-field>
<input matInput [matDatepicker]="interim_payment_[i]" placeholder="Choose a date" [ngModelOptions]="{standalone: true}"
[(ngModel)]="interim_payment_datem.date">
<mat-datepicker-toggle matSuffix [for]="interim_payment_[i]"></mat-datepicker-toggle>
<mat-datepicker [id]="interim_payment_[i]"></mat-datepicker>
</mat-form-field>
</div>
这是我的组件
export class PaymentPlanComponent implements OnInit {
interim_payment_multi = [];
constructor(private http: HttpClient) {
this.interim_payment_multi[0] = { date: null };
this.interim_payment_multi[1] = { date: null };
this.interim_payment_multi[2] = { date: null };
}
我收到此错误
ERROR TypeError: Cannot read property '0' of undefined
我该如何解决这个问题?