作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我已经在我的 app.module.ts 文件中导入了 matdatepicker,但它仍然显示一些错误。我无法让 Material 组件工作。该按钮工作正常并使用 Angular Material 组件。但是当我使用 datepicker 时它不起作用。
app.module.ts 文件
import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';
import{ HttpClientModule} from '@angular/common/http';
import {BrowserAnimationsModule} from '@angular/platform-browser/animations';
import {MatTableModule} from '@angular/material/table';
import {MatDatepickerModule} from '@angular/material/datepicker';
import {MatButtonModule} from '@angular/material/button';
import {MatFormFieldModule} from '@angular/material/form-field';
import { AppRoutingModule } from './app-routing.module';
import { AppComponent } from './app.component';
import { InactiveusersComponent } from './component/inactiveusers/inactiveusers.component';
import { CalendarComponent } from './component/calendar/calendar.component';
import { InactiveItemComponent } from './component/inactive-item/inactive-item.component';
import { NewtableComponent } from './component/newtable/newtable.component';
@NgModule({
declarations: [
AppComponent,
InactiveusersComponent,
CalendarComponent,
InactiveItemComponent,
NewtableComponent
],
imports: [
BrowserModule,
AppRoutingModule,
HttpClientModule,
BrowserAnimationsModule,
MatTableModule,
MatDatepickerModule,
MatButtonModule,
MatFormFieldModule
],
exports:[
MatDatepickerModule,
MatButtonModule
],
providers: [MatFormFieldModule,MatDatepickerModule],
bootstrap: [AppComponent]
})
export class AppModule { }
<input #startDate type="date" name="startdate">
<input #endDate type="date"name="enddate">
<button (click)="sendRange(startDate.value,endDate.value)" mat-button color="primary">Submit</button>
<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>
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.
at createMissingDateImplError (datepicker.js:37)
at new MatDatepickerInput (datepicker.js:2344)
at createClass (core.js:24577)
at createDirectiveInstance (core.js:24386)
at createViewNodes (core.js:34994)
at callViewAction (core.js:35444)
at execComponentViewsAction (core.js:35349)
at createViewNodes (core.js:35023)
at callViewAction (core.js:35444)
at execComponentViewsAction (core.js:35349)
最佳答案
我知道了,这里工作正常只需在 APP.MODULE.TS 文件中导入模块
import {MatNativeDateModule} from '@angular/material/core';
imports: [
...
MatNativeDateModule
],
关于javascript - MatDatepicker : No provider found for DateAdapter. 您必须在应用程序根目录中导入以下模块之一:MatNativeDateModule,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56503946/
我是一名优秀的程序员,十分优秀!