2016-10-29 21 views
0

模型並顯示這是我的模塊:在angular2我的組件不能結合在html

import { NgModule } from '@angular/core'; 
import { CommonModule } from '@angular/common'; 
import { FormsModule, ReactiveFormsModule } from '@angular/forms'; 
import { BrowserModule } from '@angular/platform-browser'; 

@NgModule({ 
    imports: [CommonModule, FormsModule, BrowserModule, ReactiveFormsModule], 
    declarations: [FooterComponent], 
    exports: [FooterComponent], 
    providers: [] 
}) 

export class FooterModule { } 

這是我的組件:

import { Component } from '@angular/core'; 

@Component({ 
    moduleId: module.id, 
    selector: 'FooterComponent', 
    templateUrl: 'footer.component.html' 
}) 

export class FooterComponent { 
    email: string = ""; 

    constructor() { 
    console.log("footer!"); 

    this.email = "test"; 
    } 

} 

這是我的html:

<div class="form-group col-xs-10 col-xs-offset-1 col-sm-8 col-sm-offset-2">     

    <input class="form-control" type="email" value="" placeholder="Email address" [(ngModel)]="email"> 

</div> 

我想要做的就是將模型電子郵件2種方式綁定到視圖。

錯誤我在控制檯得到的是:

未處理的承諾拒絕:模板解析錯誤:無法綁定到 「ngModel」,因爲它不是「輸入」的已知屬性。 (」

*讓我知道如果你需要了文件

+0

你也有'

'標籤嗎? –

+0

@GünterZöchbaueryeh我有一個表單標籤。我只是想讓它工作 - 非常基本的綁定 – AngularM

回答

0

BrowserModule只應在根模塊AppModule中而不是在其他模塊添加到imports。(CommonModule只需要添加非根模塊,但不會損害根模塊)