【发布时间】:2018-02-21 08:46:58
【问题描述】:
我想在整个应用程序中显示通用页眉和页脚。但是当我尝试这样做时,它会显示两次:-
app.component.html
<header>
Header
</header>
<router-outlet></router-outlet>
<footer>
Footer
</footer>
app.component.ts
import { Component } from '@angular/core';
@Component({
selector: 'app-root',
templateUrl: './app.component.html',
styleUrls: ['./app.component.css']
})
export class AppComponent {
title = 'app';
}
app.module.ts
RouterModule.forRoot([
{path: 'home', component: AppComponent},
{path: '*', redirectTo: 'home', pathMatch: 'full'},
{path: '**', redirectTo: 'home', pathMatch: 'full'}
])
结果
Header
Header
Footer
Footer
上次我通过创建页眉和页脚组件解决了这个问题。我知道如果我这样做会起作用,但我想了解为什么这是错误的......
【问题讨论】:
-
页眉和页脚组件本身实际上是什么样的? (代码)
-
我还没有创建页眉和页脚组件...上次我解决这个问题是通过创建页眉和页脚组件。但我不明白为什么这不起作用......
标签: angular angular-components router-outlet