错误:尝试打开没有关联输入的MdDatepicker

时间:2017-07-19 20:46:42

标签: angular-material2

我正在尝试the example之后的素材2日期选择器 但我一直收到这个错误

Error: Attempted to open an MdDatepicker with no associated input.
at MdDatepicker.open (material.es5.js:21344)

下面是我的实现

<md-input-container>
                                        <input mdInput 
                                               name="dobdate" 
                                               (selectedChanged)="onSelectDOBDate($event)" 
                                               [(ngModel)]="admissionModel.DOB" 
                                               [mdDatepicker]="picker" 
                                               placeholder="Choose a Date of Birth">
                                        <button mdSuffix [mdDatepickerToggle]="dobpicker"></button>
                                    </md-input-container>
                                    <md-datepicker #dobpicker></md-datepicker>

1 个答案:

答案 0 :(得分:4)

您使用错误的md-datepicker引用绑定。在[mdDatepicker]="picker"代码中将[mdDatepicker]="dobpicker"更改为input