如何使用角度(角度2或4)路线更改页面标题? [英] How to change title of a page using angular(angular 2 or 4) route?

查看:84
本文介绍了如何使用角度(角度2或4)路线更改页面标题?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

每当我单击或浏览URL栏中的链接时,我都想更改页面标题.如何使用Angular路线更改它? 我正在使用角度版本4和角度cli.

I want to change the title of the page whenever I click or browse the link from the URL bar. How to change that using Angular route? I am using angular version 4 and angular cli.

推荐答案

您可以使用@angular/platefor-browser来使用setTitle():

You can to use @angular/platefor-browser to use the setTitle():

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

@Component({
  selector: 'your-component',
})

export class YourComponent implements onInit {
  constructor(private title: Title) {}

 ngOnInit() {
     this.title.setTitle('Title for this component');
 }

}

这篇关于如何使用角度(角度2或4)路线更改页面标题?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆