[英]Can't bind to 'matDatepicker' since it isn't a known property of 'div' - Angular
I am trying to show datepicker, instead of input element I used div tag because just I need to show selected date as a label.我试图显示日期选择器,而不是使用 div 标签的输入元素,因为我只需要将所选日期显示为 label。 Below is my code.
下面是我的代码。
<mat-form-field>
<!-- <input matInput [matDatepicker]="picker" placeholder="choose a Date" (click)="picker.open()"> -->
<div matInput [matDatepicker]="picker" (click)="picker.open()"></div>
<mat-datepicker #picker></mat-datepicker>
</mat-form-field>
app.module.ts app.module.ts
import { MatDatepickerModule } from '@angular/material/datepicker';
import { MatNativeDateModule } from '@angular/material/core';
@NgModule({
imports: [
...
MatDatepickerModule,
MatNativeDateModule
]
But I am getting below error, when I run my application,但是当我运行我的应用程序时,我遇到了错误,
Error: Template parse errors: Can't bind to 'matDatepicker' since it isn't a known property of 'div'.错误:模板解析错误:无法绑定到“matDatepicker”,因为它不是“div”的已知属性。
You can use the input and make it readonly: [readonly]="true"
.您可以使用输入并将其设为只读:
[readonly]="true"
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.