2017-10-08 19 views
1

我是新角度。我在Visual Studio Code中工作。输入框不显示在角

我app.component.html看起来是这样的:

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

我app.component.ts看起来是这样的:

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

@Component({ 
    selector: 'app-root', 
    templateUrl: './app.component.html', 
    styleUrls: ['./app.component.css'] 
}) 
export class AppComponent { 
    name = ''; 
} 

我的问题是,在输入框中没有在显示浏览器http://localhost:4200/

回答

0

你缺少FormsModule导入模块:

import { FormsModule } from '@angular/forms'; 

@NgModule({ 
    imports: [ 
     ... 
     FormsModule, 
     ... 
    ], 
    declarations: [ 
     ... 
     ProfileListComponent, 
     ... 
    ] 
}) 

NgModel指令是FormsModule的一部分,因此需要导入它。你可以在这里阅读更多关于NgModel指令。

为前:跟随链接angular form

+0

它给这个错误: –

+0

无法编译。 C:/Users/Dell/my-first-app/src/app/app.module.ts(14,5):找不到名字'ProfileListComponent'。 –

+0

@Boidurja ProfileListComponent是Shashi代码的示例,因此您不需要添加ProfileListComponent ...添加组件并将FormsModule导入模块文件 – Chandru