垫选择不正确地工作 [英] mat-select Not Working Properly

查看:41
本文介绍了垫选择不正确地工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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添加到本机输入或textarea元素?

mat-form-field must contain a MatFormFieldControl. Did you forget to add matInput to the native input or textarea element?

但是,将inputmatInput包括在一起会同时显示inputmat-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.

这篇关于垫选择不正确地工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆