與 md-datapicker 繫結資料

日期選擇器 - 概述 - example.html 的:

<md-input-container>
  <input mdInput 
         [mdDatepicker]="picker" 
         [(ngModel)]="date"
         placeholder="Choose a date">
  <button mdSuffix [mdDatepickerToggle]="picker"></button>
</md-input-container>
<md-datepicker  #picker></md-datepicker>
<div>
  Date Chosen using 'ngModel':
  <div>{{ date }}</div>
</div>

日期選擇器 - 概述 - example.ts:

import {Component, OnInit} from '@angular/core';

@Component({
  selector: 'datepicker-overview-example',
  templateUrl: 'datepicker-overview-example.html'
})
export class DatepickerOverviewExample implements OnInit {
  
  date;
  
  ngOnInit(){
    this.date = new Date();
  }
  
}

現場演示