首页 > 其他 > 详细

[Angular2 Router] Setup page title with Router events

时间:2016-11-25 07:06:27      阅读:1110      评论:0      收藏:0      [点我收藏+]

Article

 

import rxjs/add/operator/filter;
import rxjs/add/operator/map;
import rxjs/add/operator/mergeMap;

import { Component, OnInit } from @angular/core;
import { Router, NavigationEnd, ActivatedRoute } from @angular/router;
import { Title } from @angular/platform-browser;

@Component({...})
export class AppComponent implements OnInit {
  constructor(
    private router: Router,
    private activatedRoute: ActivatedRoute,
    private titleService: Title
  ) {}
  ngOnInit() {
    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]));
  }
}

 

[Angular2 Router] Setup page title with Router events

原文:http://www.cnblogs.com/Answer1215/p/6100169.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!