加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > 安全 > 正文

如何在Angular Material 2中使用?

发布时间:2020-12-17 07:24:12 所属栏目:安全 来源:网络整理
导读:当Angular Material 2中的所需输入无效时,我试图显示错误消息.在 Angular Material demo app中有一个示例: form novalidate h4Inside a form/h4 md-input-container input mdInput name="example" placeholder="example" [(ngModel)]="errorMessageExample3
当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.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读