import { Title } from '@angular/platform-browser';
import { Title } from '@angular/platform-browser';
import {Component} from '@angular/core';
@Component({})
export class AppComponent {
constructor(private titleService: Title) {
// 使用this.title到处浪
}
}
// import bala...
@Component({})
export class AppComponent implements OnInit {
constructor(private titleService: Title) {
// 使用this.title到处浪
}
ngOnInit() {
this.titleService.setTitle('New Title Here');
}
}
import { Title } from '@angular/platform-browser';
import {Component} from '@angular/core';
import {Router} from '@angular/router';
@Component({})
export class AppComponent {
constructor(private titleService: Title, private router: Router) {
// 使用this.title和this.router到处浪
}
}
// import bala...
export const rootRouterConfig: Routes = [
{ path: '', redirectTo: 'home', pathMatch: 'full'},
{ path: 'home', component: HomeComponent, data: {title: 'Home-Liu'} },
{ path: 'about', component: AboutComponent, data: {title: 'About-Liu'} },
{ path: 'github', component: RepoBrowserComponent,
children: [
{ path: '', component: RepoListComponent, data: {title: 'GitHub List'} },
{ path: ':org', component: RepoListComponent,
children: [
{ path: '', component: RepoDetailComponent, data: {title: 'Repo'} },
{ path: ':repo', component: RepoDetailComponent, data: {title: 'RepoDetail'} }
]
}]
},
{ path: 'contact', component: ContactComponent, data: {title: 'Contact-Liu'} }
];
ngOnInit() {
this.router.events
.subscribe((event) => {
console.log(event); // 包括NavigationStart, RoutesRecognized, NavigationEnd
});
}
import {ActivatedRoute} from '@angular/router';
// import bala...
// other codes
ngOnInit() {
this.router.events
.subscribe((event) => {
if (event instanceof NavigationEnd) {
console.log('NavigationEnd:', event);
}
});
}
import 'rxjs/add/operator/filter';
// import bala...
// other codes
ngOnInit() {
this.router.events
.filter(event => event instanceof NavigationEnd) // 筛选原始的Observable:this.router.events
.subscribe((event) => {
console.log('NavigationEnd:', event);
});
}
import { Title } from '@angular/platform-browser';
import {Component, OnInit} from '@angular/core';
import {Router, NavigationEnd, ActivatedRoute} from '@angular/router';
import 'rxjs/add/operator/filter';
import 'rxjs/add/operator/map';
@Component({})
export class AppComponent implements OnInit {
constructor(private titleService: Title, private router: Router, private activatedRoute: ActivatedRoute) {
// 使用this.title和this.router和this.activatedRoute到处浪
}
ngOnInit() {
this.router.events
.filter(event => event instanceof NavigationEnd)
.map(() => this.activatedRoute) // 将filter处理后的Observable再次处理
.subscribe((event) => {
console.log('NavigationEnd:', event);
});
}
}
ngOnInit() {
this.router.events
.filter(event => event instanceof NavigationEnd)
.map(() => this.activatedRoute)
.map((route) => {
while(route.firstChild) {
route = router.firstChild;
}
return route;
})
.subscribe((event) => {
console.log('NavigationEnd:', event);
});
}
ngOnInit() {
this.router.events
.filter(event => event instanceof NavigationEnd)
.map(() => this.activatedRoute)
.map(route => {
while (route.firstChild) route = route.firstChild;
return route;
})
.mergeMap(route => route.data)
.subscribe((event) => this.titleService.setTitle(event['title']));
}
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';
@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']));
}
}
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有