mat-datepicker 使应用程序崩溃而不记录错误 [英] mat-datepicker makes the app crash without logged error

查看:19
本文介绍了mat-datepicker 使应用程序崩溃而不记录错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 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 基本日期选择器示例.我已经导入了 MatFormFieldModuleMatInputModuleMatDatepickerModule.

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.Material's doc on mat-datepicker 中没有明确说明依赖关系,但在某些情况下似乎是必需的.

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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆