-
StackOverflow 文档
-
angular-material2 教程
-
MD-日期选择器
-
使用事件将选定的日期值传递给函数
日期选择器 - 概述 - example.html 的:
<md-input-container>
<input mdInput [mdDatepicker]="picker" placeholder="Choose a date" [(ngModel)]="value">
<button mdSuffix [mdDatepickerToggle]="picker"></button>
</md-input-container>
<md-datepicker #picker [startAt]="startDate" (selectedChanged)="selectedDate($event)"></md-datepicker>
<p>ngModel Value: {{value}}</p>
<p>Date from selectedDate(): {{checkDate}}</p>
日期选择器 - 概述 - example.ts:
import {Component} from '@angular/core';
@Component({
selector: 'datepicker-overview-example',
templateUrl: 'datepicker-overview-example.html'
})
export class DatepickerOverviewExample {
value: Date = new Date();
checkDate: Date;
selectedDate(date){
// ngModel still returns the old value
console.log("ngModel: " + this.value);
// date passes the newly selected value
console.log("Selected Value: " + date);
this.checkDate = date;
}
}
现场演示