Angular 显示模板的内容不';行不通

Angular 显示模板的内容不';行不通,angular,angular-templatecache,Angular,Angular Templatecache,我是angular 2的新手,我用这个命令生成了一个组件 ng generate component hello 生成所有文件并更新app.module.ts 在index.html中,我添加了这个 <app-hello></app-hello> 嗯,在索引中,您只能打印“引导”中的组件。现在,app.component.html是您的主html文件,您可以在其中放置其他组件。您不能在index.html中执行此操作。尝试将引导:[AppComponent]替换为引导

我是angular 2的新手,我用这个命令生成了一个组件

ng generate component hello
生成所有文件并更新app.module.ts

index.html中,我添加了这个

<app-hello></app-hello>

嗯,在索引中,您只能打印“引导”中的组件。现在,app.component.html是您的主html文件,您可以在其中放置其他组件。您不能在index.html中执行此操作。

尝试将
引导:[AppComponent]
替换为
引导:[HelloComponent]
我们在引导中列出组件,告诉angular这些组件是我们的起点。这意味着angular将以特殊方式编译这些组件(生成宿主工厂),并将查找满足组件选择器的元素。然后在这些元素中放置组件模板。只需将索引标记更改为引导主组件
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 { }