Angular 2仅在页面上显示标题

时间:2017-03-14 14:02:31

标签: html angular typescript

我是棱角分明的2,所以请原谅我, 如何在页面不显示时显示标题:“主页或登录或注册路由”。

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

我觉得我会尝试获取路线名称和使用和if语句,但不会显示如何。请帮忙

1 个答案:

答案 0 :(得分:0)

app.component.ts

import { Router } from '@angular/router';
import { Component, OnInit } from '@angular/core';
...
...

 export class AppComponent implements OnInit {
 showHeader: boolean = true;
 constructor(private router: Router) {}

 ngOnInit() {
  // listenging to routing navigation event
  this.router.events.subscribe(event => this.modifyHeader(event));
 }

 modifyHeader(location) {
   if (location.url != "/home" && location.url != "/login" && location.url != "/register" && location.url != '/')
   {
       this.showHeader = false;
   } else {
         this.showHeader = true;
     }
}
}
app.component.html

中的

  <header *ngIf="showHeader"><header>
  <router-outlet></router-outlet>
  <footer></footer>

https://plnkr.co/edit/jUIVOfNDVVCyw2gk1Ara?p=preview