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

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

问题描述

每当我从 URL 栏中单击或浏览链接时,我都想更改页面的标题.如何使用 Angular 路由改变它?我正在使用 angular 版本 4 和 angular 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/plateform-b​​rowser 来使用 setTitle():

You can to use @angular/plateform-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天全站免登陆