我正在使用 angular 5 并遇到问题。我想动态更改我的页面标题。我已经这样做了但是我没有在页面标题后添加后缀。假设我的页面标题 Home 并且我想添加后缀为 Home | 我的标题。请帮我解决这个问题。
这是我的代码..
app.component.ts file
// imported
import {Component, OnInit} from '@angular/core';
import {Router, NavigationEnd, ActivatedRoute } from '@angular/router';
import { Title } from '@angular/platform-browser';
import 'rxjs/add/operator/filter';
import 'rxjs/add/operator/map';
import 'rxjs/add/operator/mergeMap';
this._router.events
.filter((event) => event instanceof NavigationEnd)
.map(() => this.activatedRoute)
.map((route) => {
while (route.firstChild) route = route.firstChild;
return route;
})
.filter((route) => route.outlet === 'primary')
.mergeMap((route) => route.data)
.subscribe((event) => this.titleService.setTitle(event['title']));
my routing file
{
path: '',
component: HomeComponentComponent,
pathMatch: 'full',
data: { title: 'Home' }
},
动态页面标题工作正常。我想在页面标题后添加后缀作为主页 | 我的标题请帮我解决这个问题...