我試圖使用日期選擇器。我對複選框或單選按鈕沒有任何問題。但是,當我嘗試並添加日期選擇器,我總是得到這個錯誤:角度材料日期選擇器不適用於我
我app.module.ts文件Error: Template parse errors: Can't bind to 'htmlFor' since it isn't a known property of 'md-datepicker-toggle'
:
import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';
import { MdButtonModule,
MdCheckboxModule,
MdCardModule,
MdRadioModule,
MdDatepickerModule } from '@angular/material';
import { AppComponent } from './app.component';
import { WeekControlComponent } from './week-control.component';
@NgModule({
declarations: [
AppComponent,
WeekControlComponent
],
imports: [
BrowserModule,
FormsModule,
MdButtonModule,
MdCheckboxModule,
MdCardModule,
MdRadioModule,
MdDatepickerModule
],
providers: [],
bootstrap: [AppComponent]
})
export class AppModule { }
而且我有一個WeekControlComponent:
HTML<input mdInput [mdDatepicker]="picker" placeholder="Choose a date">
<md-datepicker-toggle mdSuffix [for]="picker"></md-datepicker-toggle>
<md-datepicker #picker></md-datepicker>
TS
import { Component, OnInit } from '@angular/core';
@Component({
selector: 'app-week-control',
templateUrl: './week-control.component.html',
styleUrls: ['./week-control.component.css']
})
export class WeekControlComponent implements OnInit {
constructor() { }
ngOnInit() {
}
}
我COPIE d直接從angular.io材質示例頁面查看示例。我不明白爲什麼它不工作。有人可以幫我嗎?
我有一個工作plunker [這裏](https://plnkr.co/edit/NWIq75PQM4l7awHLygDq?p=preview),我爲答案[這裏](https://stackoverflow.com/a/46159653)。也許它會幫助:) – BogdanC