我刚刚开始学习 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”的内容?
您可以使用
@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']
})
但不能在单个组件中组合或混合两者。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句