Im trying to use the date picker. I have no issue with the checkbox or radio buttons. But when I try and add the date picker I always get this error:
Error: Template parse errors: Can't bind to 'htmlFor' since it isn't a known property of 'md-datepicker-toggle'
in my app.module.ts file:
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 { }
And I have a 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() {
    }
  }
I copied the example straight from the angular.io material examples page. I dont understand why its not working. Can someone please help me here?
If you using material version 2.0.0-beta.8 then you need to do the following changes:-
Replace code in HTML File
<md-input-container>
<input mdInput [mdDatepicker]="picker" placeholder="Choose a date">
<button mdSuffix [mdDatepickerToggle]="picker"></button>
</md-input-container>
<md-datepicker #picker></md-datepicker>
2.Add one more module in app.module i.e. MdNativeDateModule
import { MdButtonModule, 
MdCheckboxModule,
MdCardModule,
MdRadioModule, 
MdDatepickerModule, 
MdNativeDateModule   } from '@angular/material';
 imports: [
  BrowserModule, 
FormsModule,
MdButtonModule, 
MdCheckboxModule, 
MdCardModule, 
MdRadioModule,
MdDatepickerModule,
MdNativeDateModule
],
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With