1. 配置路由, 添加data.title参数
import { NgModule } from '@angular/core';
import { RouterModule, Routes } from '@angular/router'; const routes: Routes = [
{
path: '',
component: DashComponent,
data: {
title: 'Examples',
},
},
{
path: 'enumerate-devices',
component: EnumerateDevicesComponent,
data: {
title: '查看 video audio 设备列表',
},
}
]; @NgModule({
imports: [RouterModule.forRoot(routes)],
exports: [RouterModule],
})
export class AppRoutingModule {}
  1. 监听路由导航完毕,读取data.title,设置document.title
import { Component, OnInit } from '@angular/core';
import { Title } from '@angular/platform-browser';
import { Router, NavigationEnd, ActivatedRoute } from '@angular/router'; @Component({
selector: 'live-video-example-root',
templateUrl: './app.component.html',
styleUrls: ['./app.component.styl'],
})
export class AppComponent implements OnInit {
constructor(
private readonly titleService: Title,
private route: ActivatedRoute,
private readonly router: Router
) {} ngOnInit() {
this.router.events.subscribe((e) => {
if (e instanceof NavigationEnd) {
let child = this.route.firstChild;
while (child.firstChild) {
child = child.firstChild;
}
const title = child.snapshot.data['title'];
this.titleService.setTitle(title ?? 'ng app');
}
});
}
}

ng 设置动态的document title的更多相关文章

  1. react 动态修改 document.title

    装饰器 // withComponents/withHeaderBar.js import React, { Component } from "react"; import He ...

  2. 用document.title=“xxx”动态修改title,在ios的微信下面不生效

    单页应用里整个页面只会在第一次完全刷新,后面只会局部刷新(一般不包括head及里面的title),所以无法在服务器端控制title,只能在页面刷新的时候通过js修改title.常规做法如下,可惜在iO ...

  3. 【转】vue中动态设置meta标签和title标签

    因为和原生的交互是需要h5这边来提供meta标签的来是来判断要不要显示分享按钮,所有就需要手动设置meta标签,标题和内容 //router内的设置 { path: '/teachers', name ...

  4. 用document.title=“xxx”动态修改title,在ios的微信下面不生效的解决办法!

    //需要jQuery var $body = $('body'); document.title = 'title'; // hack在微信等webview中无法修改document.title的情况 ...

  5. 基于Vue的SPA动态修改页面title的方法

    最近基于VUE做个SPA手机端web发现动态修改页面标题通过document.title=xxxx 来修改着实蛋疼,而且在IOS的微信端据说没效果.百度发现要针对IOS的微信做点额外的操作,即:创建一 ...

  6. Vue项目添加动态浏览器头部title

    0. 直接上 预览链接 + 效果图 Vue项目添加动态浏览器头部title 1. 实现思路 ( 1 ) 从路由router里面得到组件的title ( 2 ) title存vuex (本项目已经封装h ...

  7. 使用vue-router设置每个页面的title

    进入 router 文件夹底下的index.js文件 首先引入: import Vue from 'vue' import Router from 'vue-router' 然后在路由里面配置每个路由 ...

  8. vue 修改单页标题 --- document.title

    方法1. 在需要的组件或者页面内设置 document.title = response.data.res.title 方法2. <head> <meta http-equiv=&q ...

  9. vue 设置动态标题

    在 router/index.js 文件中设置 meta:{title:'标题'} 和 router.beforeEach,即可实现功能, 代码如下: import { createRouter, c ...

随机推荐

  1. 拓扑排序(topo sort)之 最大食物链计数( 洛谷P4017)

    前言: 复习复习拓扑排序,自己把自己弄没了/kk 题目传送门 简化题意: 在一个DAG中,求从所有入度为0的点到所有出度为0的点路径的条数 md理解错题意把自己卡了半天,生物学的好的就可以直接理解为求 ...

  2. Web漏洞扫描-AppScan

    Web漏洞扫描-AppScan 一.AppScan简述 二.功能及特点 一.AppScan简述 IBM Security AppScan是一个适合安全专家的Web应用程序和Web服务渗透测试解决方案. ...

  3. SpringBoot启动方式,Spring Boot 定义系统启动任务

    SpringBoot启动方式,Spring Boot 定义系统启动任务 SpringBoot启动方式 1.1 方法一 1.2 方法二 1.2.1 start.sh 1.2.2 stop.sh 1.2. ...

  4. SSM框架搭建详细解析

    总结了一下搭建SSM框架流程,在以后用到的时候方便回头使用. 使用工具:MyEclipse 2015:Tomcat 8版本:jdk1.8版本. 首先: 1:创建一个WebProject项目,jdk1. ...

  5. js将金额转成大写金额

    function Chinese(){ /* var num= $(dialogStruct.iframe.contentDocument.getElementById("contractA ...

  6. CCF-交通规划-dijkstra+贪心

    交通规划 问题描述 G国国王来中国参观后,被中国的高速铁路深深的震撼,决定为自己的国家也建设一个高速铁路系统. 建设高速铁路投入非常大,为了节约建设成本,G国国王决定不新建铁路,而是将已有的铁路改造成 ...

  7. GLIBC升级

    GLIBC升级 1.安装 1.1 说明 目前大部分架构都已经是GLIBC2.14了,难免会有一些老的机器会是GLIBC2.12,所以下面是我升级GLIBC的过程及步骤. GLIBC是系统核心服务,升级 ...

  8. python实现经典排序算法

    以下排序算法最终结果都默认为升序排列,实现简单,没有考虑特殊情况,实现仅表达了算法的基本思想. 冒泡排序 内层循环中相邻的元素被依次比较,内层循环第一次结束后会将最大的元素移到序列最右边,第二次结束后 ...

  9. 关于cnblogs至github上blog的搬迁

    由于同学的强烈抗议(由于网页太卡,而且还有bug),所以在今天完成了github上blog的搭建,并且有了良好的阅读环境; Leceue

  10. 【51nod1674】区间的价值 V2(算法效率--位运算合并优化+链表实现)

    题目链接:  51nod1674 题意:规定一个区间的价值为这个区间中所有数and起来的值与这个区间所有数or起来的值的乘积.现在l有一个 N 个数的序列,问所有n*(n+1)/2个区间的贡献的和对1 ...