mat-datepicker使应用程序崩溃而没有记录错误 [英] mat-datepicker makes the app crash without logged error
问题描述
我在url /demo
<mat-form-field>
<input matInput placeholder="Choose a date">
</mat-form-field>
哪种渲染效果很好,但我将其重写为
Which renders fine, but as soon as I rewrite this as
<mat-form-field>
<input matInput [matDatepicker]="picker" placeholder="Choose a date">
<mat-datepicker-toggle matSuffix [for]="picker"></mat-datepicker-toggle>
<mat-datepicker #picker></mat-datepicker>
</mat-form-field>
该应用程序重定向到URL /
,除了空白外不显示任何内容.控制台中没有任何记录.
the app redirects to the url /
and does not displays anything but blank space. Nothing is logged in the console.
该代码之所以起作用,是因为它是从Angular Material复制的基本日期选择器示例 .我已经导入了MatFormFieldModule
,MatInputModule
和MatDatepickerModule
.
The code is supposed to work because it's copied from Angular Material basic datepicker example. I've imported MatFormFieldModule
, MatInputModule
and MatDatepickerModule
.
发生了什么事?
推荐答案
解决方案是另外导入可选的Material模块MatNativeDateModule
.在mat-datepicker
的Material的文档中没有明确说明依赖关系,但在某些情况下似乎是必需的.
A solution is to additionally import the optional Material module MatNativeDateModule
. No dependency is explicitly stated in Material's doc on mat-datepicker
, but it seems to be required in some cases.
感谢 @pengyy 在
Thanks to @pengyy 's answer on this question that helped me get to this solution.
这篇关于mat-datepicker使应用程序崩溃而没有记录错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!