[Angular2 Router] Setup page title with Router events
with Router Page setup Events title Angular2
2023-09-14 09:00:52 时间
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'])); } }
相关文章
- C.R.E.A.M Hack with Yearn
- Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception
- 【论文学习】End-to-End Object Detection with Transformers
- ORA-02096: specified initialization parameter is not modifiable with this option ORACLE 报错 故障修复 远程处理
- ORA-29813: non-supported object type with associate statement ORACLE 报错 故障修复 远程处理
- ORA-60010: adding (string) blocks to LOB segment string.string with MAXSIZE (string) ORACLE 报错 故障修复 远程处理
- MySQL Error number: MY-011127; Symbol: ER_SEMISYNC_TRACE_EXIT_WITH_INT_EXIT_CODE; SQLSTATE: HY000 报错 故障修复 远程处理
- ORA-15083: failed to communicate with ASMB background process ORACLE 报错 故障修复 远程处理
- Batch Rename with Linux: Unlocking a Powerful Tool(批量重命名linux)
- Maximizing Network Efficiency with Linux Router Technology(routerlinux)
- Setting up your TPLink router on Linux made easy with these simple steps(tplinklinux)
- Boost Your Version Control with Subsvn on Linux: A Comprehensive Guide(subsvnlinux)
- Learn How to Check Server Time with Linux Command(linux查看服务器时间)
- Securely Manage Your Oracle Database with SSH Access(sshoracle)
- 分析学习Oracle深入理解使用With 分析(oracle使用with)
- MySQL查询优化使用WITH子句的限制与替代方案(mysql不能用with)