gpt4 book ai didi

angular - 如何在 Angular Material 2 中使用

转载 作者:太空狗 更新时间:2023-10-29 17:14:35 24 4
gpt4 key购买 nike

当所需输入在 Angular Material 2 中无效时,我试图显示一条错误消息。Angular Material demo app 中有一个示例:

<form novalidate>
<h4>Inside a form</h4>

<md-input-container>
<input mdInput name="example" placeholder="example"
[(ngModel)]="errorMessageExample3" required>
<md-error>This field is required</md-error>
</md-input-container>

<button color="primary" md-raised-button>Submit</button>
</form>

Expected result

不幸的是,当我尝试做同样的事情时,我得到:

Unhandled Promise rejection: Template parse errors:
'md-error' is not a known element:
1. If 'md-error' is an Angular component, then verify that it is part
of this module.
2. If 'md-error' is a Web Component then add 'CUSTOM_ELEMENTS_SCHEMA'
to the '@NgModule.schemas' of this component to suppress this message.

我应该怎么做才能使用 <md-error>

最佳答案

您是否已将 MaterialModule 添加到您的 appModule?

@NgModule({
imports: [
...
MaterialModule
],
...
})

更新:

md-error 是一个尚未发布的新指令(从 beta.2 开始),我猜它可能会成为下一个版本的一部分。可以在此处找到更多信息:https://github.com/angular/material2/pull/3560

同时你可以使用md-hint

关于angular - 如何在 Angular Material 2 中使用 <md-error>?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43090620/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com