【发布时间】:2018-06-21 13:05:06
【问题描述】:
我已经开始学习使用 Angular,到目前为止,它看起来相当简单。我选择转换我现有的网站主题之一以熟悉该过程,但遇到了有关正确使用的问题。
到目前为止,我的理解是每个页面都是一个组件。我在 app.component.html 中有我的索引内容,然后每个子页面也是一个单独的组件。但是,我想将header/footer HTML 分开,并像过去在 PHP 中那样包含它。
我的问题是,header/footer 应该是单个组件还是应该只是单个 HTML 文件,包括使用 ng-include?我意识到两者都可以,但不知道哪个是 Angular 开发人员的传统实现。
我正在尝试以下方法,但页眉/页脚组件似乎没有加载。它们在 app.component.html 中运行良好,但在 index.html 中运行良好。
index.html
<body>
<app-header></app-header>
<app-root></app-root>
<app-footer></app-footer>
</body>
app.module.ts
import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';
import { AppComponent } from './app.component';
import { HeaderComponent } from './header/header.component';
import { FooterComponent } from './footer/footer.component';
import { ProductComponent } from './product/product.component';
import { ProductsComponent } from './products/products.component';
@NgModule({
declarations: [
AppComponent,
HeaderComponent,
FooterComponent,
ProductComponent,
ProductsComponent
],
imports: [
BrowserModule
],
providers: [],
bootstrap: [AppComponent]
})
export class AppModule { }
【问题讨论】:
标签: javascript php html css angular