-1
我想在我的应用程序中显示常见的页眉和页脚。但是,当我尝试这样做,它就会显示两次: -Angular 2为什么渲染应用程序组件模板两次
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
上次我通过为页眉和页脚创建组件来解决此问题。我知道,如果我这样做,将工作,但我想知道为什么这是错的....
页眉和页脚组件本身的外观如何? (code) –
我还没有创建页眉和页脚组件...上次我解决这个问题是通过创建页眉和页脚组件。但我不明白为什么这不起作用... –