Angular Material 2 : 'md-input' is not a known element

标签 angular angular-material

我在这里缺少什么? md-input 是否应该单独加载到 module 文件中?

这有效:

<md-input-container>
  <input mdInput name="username" placeholder="Username" [(ngModel)]="username" #name="ngModel" required>          
</md-input-container>

但是,这失败了:

<md-input placeholder="amount" align="end">
  <span md-prefix>$&nbsp;</span>
  <span md-suffix>.00</span>
</md-input>

出现以下错误:

Unhandled Promise rejection: Template parse errors:
'md-input' is not a known element:
1. If 'md-input' is an Angular component, then verify that it is part of this module.
2. If 'md-input' is a Web Component then add "CUSTOM_ELEMENTS_SCHEMA" to the '@NgModule.schemas' of this component to suppress this message. ("
  </div>
  <div>
    [ERROR ->]<md-input placeholder="amount" align="end">
      <span md-prefix>$&nbsp;</span>

app.module.ts

import { NgModule }      from '@angular/core';
import { CommonModule }   from "@angular/common";
import { BrowserModule } from '@angular/platform-browser';
import { FormsModule } from "@angular/forms";
import { MaterialModule } from "@angular/material";

import { AppComponent }  from './app.component';

import "hammerjs";

@NgModule({
  imports:      [ 
    CommonModule,
    BrowserModule, 
    FormsModule,
    MaterialModule.forRoot() 
  ],
  declarations: [ AppComponent ],
  bootstrap:    [ AppComponent ]
})
export class AppModule { }

最佳答案

那是因为在你的第二个示例中语法是错误的。在最新的 2.0.0 beta .1(我想您正在使用)中,md-input 关键字已替换为 mdInput。因此,如果您想要使用 Angular Material 2 设计输入样式,只需输入

<md-input-container>
    <input mdInput placeholder="Username" name="username">
 </md-input-container>

关于 Angular Material 2 : 'md-input' is not a known element,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42673201/

相关文章:

angular - app.module.ts 文件有什么用,我应该在里面做什么?

javascript - 重用 Angular 和 html 的冗余函数

angular - 在 mat-select 中设置默认选项

arrays - 元素数组不会被接口(interface)填充

javascript - 如何在上传图片之前检查 Angular 中的图片方向

angular - 如何对 Angular Material 表中其他语言字符的数据进行排序?

javascript - 使用 Angular Material 将 FAB 放在 seam 上

css - 悬停时显示垫子图标

angular - ngFor 不显示来自 Observable 事件源的数据

angular - 使用 Angular Material 按列过滤谓词表