Angular 角度/材质/日期选择器-找不到DateAdapter的提供程序
我有一个问题:Angular 角度/材质/日期选择器-找不到DateAdapter的提供程序,angular,typescript,datepicker,material-design,angular6,Angular,Typescript,Datepicker,Material Design,Angular6,我有一个问题:angular/material/datepicker 我有一个虚拟项目,可以正确处理以下文件: /src/app/app.module.ts import { BrowserModule } from '@angular/platform-browser'; import { NgModule } from '@angular/core'; import { FormsModule, ReactiveFormsModule } from '@angular/forms'; imp
angular/material/datepicker
我有一个虚拟项目,可以正确处理以下文件:
/src/app/app.module.ts
import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';
import { FormsModule, ReactiveFormsModule } from '@angular/forms';
import { BrowserAnimationsModule } from '@angular/platform-browser/animations';
import { MatStepperModule, MatInputModule, MatButtonModule, MatNativeDateModule } from '@angular/material';
import { MatDatepickerModule } from '@angular/material/datepicker';
import { AppComponent } from './app.component';
import { StepperComponent } from './components/stepper/stepper.component';
import { DatepickerComponent } from './components/datepicker/datepicker.component';
@NgModule({
declarations: [
AppComponent,
StepperComponent,
DatepickerComponent,
],
imports: [
BrowserModule,
FormsModule,
ReactiveFormsModule,
BrowserAnimationsModule,
MatStepperModule,
MatInputModule,
MatButtonModule,
MatNativeDateModule,
MatDatepickerModule,
],
providers: [],
bootstrap: [ AppComponent ]
})
export class AppModule { }
/src/app/components/datepicker/datepicker.component.html
<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>
在API
部分,他们没有提到该模块
他们在概述
部分提到了该模块,但没有提供太多细节
你能帮我清理一下吗?这有时看起来很模糊
谢谢 这样做的目的是让开发人员可以选择他们想要的日期提供者,而不受任何限制,因此他们没有在概述下提到它,而不是在API下提到它,因为API只是用于角材料设计的核心API,它为您提供了对特定材料组件的控制和可访问性
matNativeDateModule
不是通过对时间进行解析而整体开发的模块,只是告诉matDatePicker
嘿,当您使用日期对象时,请使用本机javascript日期对象。您可能不想使用它,也不想使用自己的日期对象或javascript日期库,比如。在导入中交换MatNativeDateModule
和MatDatepickerModule
的顺序什么?为什么?您能解释一下您的意思吗?我猜MatNativeDateModule需要在MatDatepickerModule之后构建,这可能是问题的原因。核心路由模块和动画模块具有类似的效果。导入的顺序很重要,示例中也有这样的顺序!但我的问题不是关于订单,而是为什么如果我删除该导入,会出现错误?谢谢!对不起,我看错了。模块MatNativeDateModule
有一个名为DateAdapter
的服务,该服务需要由父模块提供才能注入。这就是provider/@Injector标记的作用。由于不导入MatNativeDateModule
,因此没有模块提供可注入的DateAdapter
,因此会引发错误。
ERROR Error: "MatDatepicker: No provider found for DateAdapter. You must import one of the following modules at your application root: MatNativeDateModule, MatMomentDateModule, or provide a custom implementation."