Angular 12 日期选择器

Rod*_*igo 9 javascript datepicker angular-material angular angular12

我尝试在 Angular 12 中使用材质日期选择器,但出现错误:

main.js:1错误错误:未捕获(承诺中):TypeError:无法读取null的属性“localeChanges”TypeError:无法读取null的属性“localeChanges”

关于其他在 Angular 12 上正常工作的日期选择器有什么建议吗?

小智 35

import { MatDatepickerModule } from '@angular/material/datepicker';
import { MatNativeDateModule } from '@angular/material/core';

....

imports: [
   MatInputModule,
   MatDatepickerModule,
   MatNativeDateModule
]
Run Code Online (Sandbox Code Playgroud)

将这两个导入到您的 app.module.ts 中

这里的顺序很重要,MatInputModule应该在之前导入MatDatepickerModule

  • 这解决了我的问题。他们仍然没有将其添加到文档中。 (2认同)