I don't understand this error. I'm trying to use the mat-datepicker with MomentJS exactly as shown in the examples, but I cannot get rid of this error.
My component code looks like this:
import { Component,
Input,
OnInit } from '@angular/core';
import { TimeRange, TimeRanges } from "./time-range-selector.constants";
import * as moment from 'moment';
import {FormControl} from "@angular/forms";
@Component({
selector: 'time-range-selector',
templateUrl: './time-range-selector.component.html',
styleUrls: ['./time-range-selector.component.scss']
})
export class TimeRangeSelectorComponent implements OnInit {
private _timeRange: TimeRange;
public timeRanges: {} = TimeRanges;
public startDate: FormControl = new FormControl(moment([2017, 0, 1]));
public endDate: FormControl = new FormControl(moment([2017, 0, 2]));
public get selectedTimeRange(): TimeRange {
return this._timeRange;
}
@Input()
public set selectedTimeRange(range: TimeRange) {
this._timeRange = range;
}
constructor() { }
ngOnInit() {
}
}
and my markup like this:
<div class="time-range-selector">
<mat-form-field>
<mat-select placeholder="Time Range">
<mat-option *ngFor="let timeRange of timeRanges" [value]="timeRange.value">
{{ timeRange.label }}
</mat-option>
</mat-select>
</mat-form-field>
<!-- start date -->
<mat-form-field *ngIf="true">
<input matInput [matDatepicker]="startDate" placeholder="Choose a date" [formControl]="startDate">
<mat-datepicker-toggle matSuffix [for]="endDate"></mat-datepicker-toggle>
<mat-datepicker #startDate></mat-datepicker>
</mat-form-field>
<!-- end date -->
<mat-form-field *ngIf="true">
<input matInput [matDatepicker]="endDate" placeholder="Choose a date" [formControl]="endDate">
<mat-datepicker-toggle matSuffix [for]="endDate"></mat-datepicker-toggle>
<mat-datepicker #endDate></mat-datepicker>
</mat-form-field>
</div>
The console output says the error occurs at the line beginning <input matInput [matDatepicker]="startDate".