2017-06-20 98 views
0

enter image description here未捕獲的錯誤:模板解析錯誤:

我收到此錯誤。我搜索了谷歌,它建議我將FormsModule添加到app.module.ts。雖然我沒有,我沒有能夠解決problem.Can有人幫助我從這個

app.module.ts

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

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

@NgModule({ 
    declarations: [ 
    AppComponent, 

    ], 
    imports: [ 
    BrowserModule, 
    FormsModule, 
    ReactiveFormsModule 
    ], 
    providers: [], 
    bootstrap: [AppComponent] 
}) 
export class AppModule { } 

app.component.html

<input type="text" [{ngModel}]="name" /> 
<p> 
    {{name}} 
</p> 

回答

1

糾正你的模板

<input type="text" [(ngModel)]="name" /> 

,而不是

<input type="text" [{ngModel}]="name" /> 
1

語法因爲你的雙向綁定是不正確的。這

[{ngModel}] 

應該是這樣的:

[(ngModel)] 

使用括號,而不是大括號。這裏的訣竅就是想:在香蕉是()的盒子裏的香蕉和盒子是[]。

+0

LMAO愛協會 –

相關問題