2017-08-14 41 views
0

我只是在運行一些基本的默認鍋爐板代碼,我編輯這個文件:AngularJS,輸入文本框甚至沒有顯示

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 = ''; 
} 

但是,這從字面上什麼都不做。只有一個空白頁面。我究竟做錯了什麼?這似乎很基本

回答

1

由於ngModel指令包含在FormsModule中,所以您必須在AppModuleimports元數據選項中導入並添加該模塊。

代碼

import { NgModule }  from '@angular/core'; 
import { FormsModule }  from '@angular/forms'; //<-- FormsModule import 
import { BrowserModule } from '@angular/platform-browser'; 
import { AppComponent } from './app.component'; 

@NgModule({ 
    imports:  [ BrowserModule, FormsModule ], //<-- added FormsModule to imports option 
    declarations: [ AppComponent ], 
    bootstrap: [ AppComponent ] 
}) 
export class AppModule { } 

Demo Here

+0

我沒有看到任何地方的AppModule,HTTP://i.imgur.com/rylpbQE.png – Bana

+0

@Bana沒辦法,請plunker的.. 'app.module.ts'是你正在尋找的文件。 –

+0

感謝兄弟。它正在工作。但我很好奇,爲什麼沒有提供?我正在觀看一個教程,他只是做了相同的基本創作,並簡單地使用'[(ngModule)]'蝙蝠而不需要任何這個? – Bana

相關問題