angular2路由切換改變頁面title的示例代碼
angular2里默認切換路由或者切換組件,頁面的title是不會變化的。
angular2在路由設置里提供了data參數(shù)可以傳值,如下
{
path: 'home',
component: HomeComponent,
data: { title: 'Home', aaa: 'aaaa', bbb: 'bbbb', ccc: "cccc"}
}
path和component是常用的屬性,path是地址欄的顯示,component是調(diào)用的組件。
data則可以傳數(shù)據(jù),在組件內(nèi)可以調(diào)用。
參數(shù)調(diào)用
angular2提供Title服務可以修改title。
路由內(nèi)獲取設置的參數(shù)可以用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);
}
以上就是本文的全部內(nèi)容,希望對大家的學習有所幫助,也希望大家多多支持腳本之家。
相關(guān)文章
angularJs提交文本框數(shù)據(jù)到后臺的方法
今天小編就為大家分享一篇angularJs提交文本框數(shù)據(jù)到后臺的方法,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧2018-10-10
詳解Angular中通過$location獲取地址欄的參數(shù)
這篇文章主要介紹了詳解 Angular中通過$location獲取地址欄的參數(shù),小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧2018-08-08
Angular的Bootstrap(引導)和Compiler(編譯)機制
這篇文章主要介紹了Angular的Bootstrap(引導)和Compiler(編譯)機制的相關(guān)資料,非常不錯,具有參考借鑒價值,需要的朋友可以參考下2016-06-06
解決nodejs中使用http請求返回值為html時亂碼的問題
下面小編就為大家?guī)硪黄鉀Qnodejs中使用http請求返回值為html時亂碼的問題。小編覺得挺不錯的,現(xiàn)在就分享給大家,也給大家做個參考。一起跟隨小編過來看看吧2017-02-02

