如何隐藏首页的页脚组件?

问题描述 投票:0回答:1

这是我的app.component.html文件:

<app-header></app-header>
<router-outlet></router-outlet>
<app-footer></app-footer>

但是我想在/home路线中隐藏页脚组件。我怎样才能做到这一点? (请让我知道是否需要添加更多代码或信息?)

angular routes components show-hide
1个回答
1
投票

您可以从路径中知道您在home组件中:

In app.component.ts

page: string;

//See what is the current page from the path
this.page = this.route.parent.snapshot.url[0].path;

so in app.component.html

<app-header></app-header>
<router-outlet></router-outlet>
<app-footer *ngIf="page != 'home" ></app-footer>

因此,如果您在home组件中,则不显示页脚组件。

© www.soinside.com 2019 - 2024. All rights reserved.