【发布时间】:2020-04-08 18:19:26
【问题描述】:
我想根据 Angular 中的当前 url 更改某个标题。所以 component.ts 看起来像这样:
import {Router} from '@angular/router';
//code
public name: string
constructor(
public router: Router
) {}
getName()
{
if(this.router.url === "/some_list")
{this.name = "List"}
else if(this.router.url === "/detail")
{this.name = "Detail"}
}
然后
<a>{{this.name}}</a>
现有的答案,如How to detect a route change in Angular? 无法告诉我在路由更改后如何做某事(更改 = 真或假)。 那么如何在 url 发生变化的时候运行这个函数,让标题按照当前的视图呢?
【问题讨论】:
标签: angular routing angular-router