2017-07-12 25 views
0

我是新與角2,我已經產生了組件使用此命令顯示內容不工作

ng generate component hello 

和生成的所有文件和app.module.ts被更新。

的index.html我加入這個

<app-hello></app-hello> 

但網頁變成空白,什麼都沒有出現。

app.module.ts

import { BrowserModule } from '@angular/platform-browser'; 
import { NgModule } from '@angular/core'; 

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

@NgModule({ 
declarations: [ 
AppComponent, 
HelloComponent 
], 
imports: [ 
BrowserModule 
], 
providers: [], 
bootstrap: [AppComponent] 
}) 
export class AppModule { } 

enter image description here

+1

嘗試用'bootstrap:[HelloComponent]替換'bootstrap:[AppComponent]' – yurzui

+1

我們列出了bootstrap中的組件,告訴角度這些組件是我們的出發點。這意味着角將以特殊的方式編譯這些組件(生成主機工廠)並且將尋找滿足組件選擇器的元素。然後在這些元素裏面放置組件template.https://stackoverflow.com/questions/44077178/what-does-it-mean-to-bootstrap-an-angular-application/44077696#44077696 – yurzui

+0

只需改變你的標籤引導程序主要組件的索引

回答

0

好,內部指標,你可以只打印您在 '引導' 有分量。現在,app.component.html是您可以放置​​其他組件的主要html文件。你不能在index.html中這樣做。