源码网商城,靠谱的源码在线交易网站 我的订单 购物车 帮助

源码网商城

angular2路由切换改变页面title的示例代码

  • 时间:2020-07-30 12:50 编辑: 来源: 阅读:
  • 扫一扫,手机访问
摘要:angular2路由切换改变页面title的示例代码
angular2里默认切换路由或者切换组件,页面的title是不会变化的。 angular2在路由设置里提供了data参数可以传值,如下
{

path: 'home',

component: HomeComponent,

data: { title: 'Home', aaa: 'aaaa', bbb: 'bbbb', ccc: "cccc"}

}
path和component是常用的属性,path是地址栏的显示,component是调用的组件。 data则可以传数据,在组件内可以调用。 [b]参数调用[/b] angular2提供Title服务可以修改title。 路由内获取设置的参数可以用ActivatedRoute的snapshot的data属性获取 如下:
import { ActivatedRoute } from '@angular/router';

import { Title } from '@angular/platform-browser';

config: any;

constructor(

private route: ActivatedRoute,

private titleService: Title

) { }

ngOnInit(): void {

// Get the config information from the app routing data

this.config = this.route.snapshot.data;

// Sets the page title

this.titleService.setTitle(this.config.title);

}
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持编程素材网。
  • 全部评论(0)
联系客服
客服电话:
400-000-3129
微信版

扫一扫进微信版
返回顶部