问题
使用Angular Material 2的md-form-field报未知元素的错误。错误信息如下:
Uncaught Error: Template parse errors:
'md-form-field' is not a known element:
1. If 'md-form-field' is an Angular component, then verify that it is part
of this module.
2. If 'md-form-field' is a Web Component then add 'CUSTOM_ELEMENTS_SCHEMA'
to the '@NgModule.schemas' of this component to suppress this message. (" [ERROR ->]
解决
<md-form-field>为Angular Material 2.0.0-beta.10新增的选择器。
1、使用<md-form-field>,需要先安装Angular Material 2.0.0-beta.10以上版本
npm install --save @angular/material
2、在AppModule导入MdFormFieldModule
import { MdFormFieldModule } from '@angular/material';
@NgModule({
imports: [
....
MdFormFieldModule,
....
]