尝试在 html 中使用 mat-select 时......它不起作用。
<mat-form-field appearance="fill">
<mat-select>
<mat-option value="one">First option</mat-option>
<mat-option value="two">Second option</mat-option>
</mat-select>
</mat-form-field>
结果显示如下
PS我已经在app.module.ts文件中的imports下导入import {MatNativeDateModule} from '@angular/material/core';
并添加了MatNativeDateModule
在 app.module.ts 文件和导入部分中添加 MatSelectModule 后,现在选择控件和选项不可见。
下面是我的 app.module.ts 文件
import { NgModule,CUSTOM_ELEMENTS_SCHEMA} from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { BrowserAnimationsModule } from '@angular/platform-browser/animations';
import {FormsModule, ReactiveFormsModule} from '@angular/forms';
import {MatSelectModule} from '@angular/material/select';
import {MatFormFieldModule} from '@angular/material/form-field';
import {MatNativeDateModule} from '@angular/material/core';
import { AppComponent } from './app.component';
@NgModule({
declarations: [
AppComponent,
],
imports: [
BrowserModule,
MatNativeDateModule,
FormsModule,
ReactiveFormsModule,
MatSelectModule,
MatFormFieldModule,
BrowserAnimationsModule
],
schemas: [ CUSTOM_ELEMENTS_SCHEMA],
providers: [],
bootstrap: [AppComponent]
})
export class AppModule { }