【问题标题】:Angular Material Datepicker won't show in the pageAngular Material Datepicker 不会显示在页面中
【发布时间】:2020-07-07 09:09:40
【问题描述】:

我正在尝试将 Angular Material 日期选择器添加到页面。我一直像这样关注official doc's example,但我的页面中没有显示任何内容。

app.component.html 中有:

<section>
  <mat-form-field appearance="fill">
    <mat-label>Choose a date</mat-label>
    <input matInput [matDatepicker]="picker" />
    <mat-datepicker-toggle matSuffix [for]="picker"></mat-datepicker-toggle>
    <mat-datepicker #picker></mat-datepicker>
  </mat-form-field>
</section>

app.component.ts,我有:

import { Component } from '@angular/core';

@Component({
  selector: 'app-root',
  templateUrl: './app.component.html',
  styleUrls: ['./app.component.css'],
})
export class AppComponent {
  panelOpenState = false;
}

这是我的app.module.ts

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

import { AppComponent } from './app.component';
import { BrowserAnimationsModule } from '@angular/platform-browser/animations';

import { MatDatepickerModule } from '@angular/material/datepicker';
import { MatFormFieldModule } from '@angular/material/form-field';
import { MatInputModule } from '@angular/material/input';

@NgModule({
  declarations: [AppComponent],
  imports: [
    BrowserModule,
    BrowserAnimationsModule,
    MatDatepickerModule,
    MatFormFieldModule,
    MatInputModule,
  ],
  providers: [],
  bootstrap: [AppComponent],
})
export class AppModule {}

谁能告诉我我做错了什么?

【问题讨论】:

    标签: angular datepicker angular-material mat-datepicker


    【解决方案1】:

    我认为你没有在@NgModule 中导入FormsModule

    请检查以下示例及其main.ts 文件。它正在工作。

    Demo Example

    我希望它会有所帮助。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2019-04-04
      • 2018-08-08
      • 1970-01-01
      • 1970-01-01
      • 2023-01-13
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多