mat-datepicker makes the app crash without logged error

瘦欲@ 提交于 2019-12-25 02:25:41

问题


I've got this page component template at the 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>

the app redirects to the url / and does not displays anything but blank space. Nothing is logged in the console.

The code is supposed to work because it's copied from Angular Material basic datepicker example. I've imported MatFormFieldModule, MatInputModule and MatDatepickerModule.

What is happening?


回答1:


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.

Thanks to @pengyy 's answer on this question that helped me get to this solution.



来源:https://stackoverflow.com/questions/52388827/mat-datepicker-makes-the-app-crash-without-logged-error

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!