2017-05-14 191 views
1

我正在嘗試在Angular應用中使用mdl-select組件。材料設計light mdl-select

<form [formGroup]="form"> 
    <mdl-select formControlName="personId"> 
    <mdl-option *ngFor="let p of people" [value]="p.id">{{p.name}}</mdl-option> 
    </mdl-select> 
</form> 

我安裝使用從這裏的說明:https://github.com/mseemann/angular2-mdl-ext/tree/master/src/components/select

得到這個控制檯錯誤:

Unhandled Promise rejection: Template parse errors: 
Can't bind to 'value' since it isn't a known property of 'mdl-option'. 
1. If 'mdl-option' is an Angular component and it has 'value' input, then verify that it is part of this module. 
2. If 'mdl-option' is a Web Component then add 'CUSTOM_ELEMENTS_SCHEMA' to the '@NgModule.schemas' of this component to suppress this message. 
3. To allow any property add 'NO_ERRORS_SCHEMA' to the '@NgModule.schemas' of this component. ("tiple="true" placeholder="Select users"> 
     <mdl-option mdl-ripple *ngFor="let hero of heroes" [ERROR ->][value]="hero.name">{{hero.name}}</mdl-option> 
     </mdl-select> 

"): ng:///AppModule/[email protected]:59 
+0

您的導入是什麼樣的?每當我遇到這個問題時,它都是一個導入或引導問題 –

+0

就像這裏的指令一樣。 https://github.com/mseemann/angular2-mdl-ext/tree/master/src/components/select。我使用'@ angular-mdl/select';'在需要選擇的組件中輸入{MdlSelectModule}。 – Ciprian

+0

你可以嘗試'@ angular-mdl/option';'import {MdlOptionComponent}? –

回答

0

你的問題是,你是不是導入模塊屬性,它需要引導你的根app.module.ts

從您的自定義組件中取出import { MdlSelectModule } from '@angular-mdl/option',並將其移動到app.module.ts。此外,將MdlSelectModule添加到您的imports: []陣列中app.module.ts