0

I am using the following code to create a date picker.

<input (dateChange)="dateChanged()" class="editable-form-field" *ngIf="isEditable" [satDatepicker]="rosterHireDate" [(ngModel)]="roster.probationDate" [min]="minStartDateForClass" readonly matInput>
<sat-datepicker *ngIf="isEditable" #rosterHireDate [rangeMode]="false"></sat-datepicker>
<sat-datepicker-toggle *ngIf="isEditable" style="position: absolute; right: 0;" matSuffix [for]="rosterHireDate"></sat-datepicker-toggle>

But when I try to create multiple date pickers like below it throws an error

<ng-template ngFor let-roster [ngForOf]="rosters" let-i="index">
    <input (dateChange)="dateChanged()" class="editable-form-field" *ngIf="isEditable" [satDatepicker]="rosterHireDate" [(ngModel)]="roster.probationDate" [min]="minStartDateForClass" readonly matInput>
    <sat-datepicker *ngIf="isEditable" #rosterHireDate [rangeMode]="false"></sat-datepicker>
    <sat-datepicker-toggle *ngIf="isEditable" style="position: absolute; right: 0;" matSuffix [for]="rosterHireDate"></sat-datepicker-toggle>
</ng-template>

Error:

ERROR TypeError: Cannot read property 'rangeMode' of undefined
    at SatDatepickerInput._minValidator (saturn-datepicker.js:4215)
    at forms.js:658
    at Array.map (<anonymous>)
    at _executeValidators (forms.js:658)
    at SatDatepickerInput._validator (forms.js:623)
    at SatDatepickerInput.push../node_modules/saturn-datepicker/fesm5/saturn-datepicker.js.SatDatepickerInput.validate (saturn-datepicker.js:4522)
    at forms.js:923
    at forms.js:658
    at Array.map (<anonymous>)
    at _executeValidators (forms.js:658)

Then I realized I have to supply a different # value but not sure how to do that. Is there a way to create multiple date pickers with dynamically generated ids?

I am using a third party date picker called saturn date picker because we want to be able to select range of dates in other parts of the application.

Krishna Chaitanya
  • 2,533
  • 4
  • 40
  • 74
  • there might be some other issue bcs [Template reference variables(# hastag) are scoped to the template they are defined in](https://stackoverflow.com/a/44441164/5621827) – jitender Aug 20 '19 at 05:45
  • 1
    [also check this example](https://stackblitz.com/edit/angular-mitblz) – jitender Aug 20 '19 at 05:54

0 Answers0