2017-06-20 130 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爱协会 –

相关问题