我有一个重要的datepicker,我想在click上打开它,所以我使用了startDatePicker.open(),但是我希望使用onStartDateFocus在ts内部调用它。当我尝试使用@viewchild时,如何获得错误。
<div class="form-group">
<label for="startdate">start date</label>
<div class="input-group icon" (click)="startDatePicker.open();onStartDateFocus();">
<i class="icon date" [ngClass]="{'selected': startDate}"></i>
<input matInput #="mm/dd/yyyy" md-hide-icons="calendar" class="form-control date input" (click)="startDatePicker.open();onStartDateFocus()"
[value]="startDate" [ngModel]="startDate | date: 'MM/dd/yyyy'">
<mat-datepicker #startDatePicker [ngClass]="{'show': showStartDate}">
</mat-datepicker>
</div>
</div>
TS:
export class datepickComponent {
onStartDateFocus() {
this.showStartDate = true;
if (!this.startDate || this.startDate == 'Invalid Date') {
const date = new Date();
this.startDate = date;
}
}
}