mat-select 无法正常工作 [英] mat-select Not Working Properly
问题描述
mat-select
元素很有趣.见下文.
The mat-select
element is acting funny. See below.
代码
<mat-form-field>
<input matInput placeholder="Name" #NameInput>
</mat-form-field>
<mat-select placeholder="How Many?">
<mat-option>One</mat-option>
<mat-option>Two</mat-option>
<mat-option>Three</mat-option>
<mat-option>Four</mat-option>
<mat-option>Five</mat-option>
</mat-select>
结果
将 mat-select
包装在 mat-form-field
中给我以下错误:
Wrapping the mat-select
in a mat-form-field
gives me the following error:
mat-form-field 必须包含一个 MatFormFieldControl.你忘记了吗将 matInput 添加到原生 input 或 textarea 元素?
mat-form-field must contain a MatFormFieldControl. Did you forget to add matInput to the native input or textarea element?
然而,包括一个 input
和 matInput
显示了 input
和 mat-select
在一起,使得它看起来很奇怪.有什么办法可以解决这个问题吗?
However, including an input
with matInput
shows both the input
and the mat-select
together, making it look weird. Any way around this?
推荐答案
我傻了,我忘了在我的 app.module.ts
中导入 MatSelectModule.
Silly me, I forgot to import MatSelectModule in my app.module.ts
.
这篇关于mat-select 无法正常工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!