打开日历后角材料日期选择器错误

时间:2021-07-23 15:19:40

标签: angular angular-material

我刚刚创建了一个 angular 12(也是 11)的新项目,当我尝试添加文档中描述的日期选择器时:https://material.angular.io/components/datepicker/overview 一旦我点击按钮显示日历

core.js:6479 ERROR Error: Invalid date "1" for month with index "6".
    at NativeDateAdapter.createDate (core.js:641)
    at MatMonthView._init (datepicker.js:978)
    at SafeSubscriber._next (datepicker.js:871)
    at SafeSubscriber.__tryOrUnsub (Subscriber.js:183)
    at SafeSubscriber.next (Subscriber.js:122)
    at Subscriber._next (Subscriber.js:72)
    at Subscriber.next (Subscriber.js:49)
    at MergeMapSubscriber.notifyNext (mergeMap.js:70)
    at SimpleInnerSubscriber._next (innerSubscribe.js:10)
    at SimpleInnerSubscriber.next (Subscriber.js:49)

这就是我的 app.module.ts 的样子

import { NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';

import { AppRoutingModule } from './app-routing.module';
import { AppComponent } from './app.component';
import { BrowserAnimationsModule } from '@angular/platform-browser/animations';
import {MatFormFieldModule} from "@angular/material/form-field";
import {MatDatepickerModule} from "@angular/material/datepicker";
import {MatInputModule} from "@angular/material/input";
import {MatNativeDateModule} from "@angular/material/core";

@NgModule({
  declarations: [
    AppComponent
  ],
  imports: [
    BrowserModule,
    AppRoutingModule,
    BrowserAnimationsModule,
    MatFormFieldModule,
    MatDatepickerModule,
    MatInputModule,
    MatNativeDateModule
  ],
  providers: [],
  bootstrap: [AppComponent]
})
export class AppModule { }
这里是 app.component.html

<div>hello</div>
<div>
  <ng-container>
    <mat-form-field appearance="fill">
      <input matInput [matDatepicker]="picker">
      <mat-datepicker-toggle matSuffix [for]="picker"></mat-datepicker-toggle>
      <mat-datepicker #picker></mat-datepicker>
    </mat-form-field>
  </ng-container>
</div>
<router-outlet></router-outlet>

有人知道或有如何解决这个问题的经验吗?也许我错过了什么?

0 个答案:

没有答案