我刚刚开始学习Angular2并坚持我需要组合2个组件的地方。
这是我的app.component.ts
import { Component } from '@angular/core';
@Component({
selector: 'app-root',
template: './app.component.html <app-home></app-home>',
styleUrls: ['./app.component.css']
})
export class AppComponent {
mylogo = 'ABC Engineering';
headlist = ["Home", "About", "Portfolio", "Pricing", "Contact"];
technology = ["HTML", "CSS", "JavaScript", "jQuery", "AngularJS", "PHP"];
}
这是我的app.module.ts
import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';
import { FormsModule } from '@angular/forms';
import { HttpModule } from '@angular/http';
import { AppComponent } from './app.component';
import { HomeComponent } from './home/home.component';
import { AboutComponent } from './about/about.component';
@NgModule({
declarations: [
AppComponent,
HomeComponent,
AboutComponent,
],
imports: [
BrowserModule,
FormsModule,
HttpModule
],
providers: [],
bootstrap: [AppComponent]
})
export class AppModule { }
它没有显示app.component.html的输出!但它确实显示了'home.component.html'中的内容。 如何修复它以显示“app.component.html”中的内容?
答案 0 :(得分:4)
您可以使用
@Component({
selector: 'app-root',
templateUrl: './app.component.html',
styleUrls: ['./app.component.css']
})
或
@Component({
selector: 'app-root',
template: '<app-home></app-home>',
styleUrls: ['./app.component.css']
})
但不能在单个组件中组合或混合。