当所需的输入在Angular Material 2中无效时,我试图显示一条错误消息。Angular Material演示应用程序中有一个示例:
<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>
不幸的是,当我尝试做同样的事情时,我得到:
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
。
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句