Rav*_*avy 9 angular2-template angular2-routing angular
因此,我想在特定页面被击中时使我的Header上的锚元素消失.当该页面被击中时,如何在*ngIf中捕获url.
我有一个标题,所有页面都保持相同.当我在/ home路由时,只需要隐藏一个锚元素.如何在*ngIf中捕获这个"/ home"?
*ngIf ="href ='/ home'"无效.任何替代品?
Arv*_*ous 17
//mycomponent.component.ts
class MyComponent {
constructor(private router: Router){
}
}
//mycomponent.component.html
<div *ngIf="router.url === '/some/route'">
</div>Run Code Online (Sandbox Code Playgroud)
我来到此页面是因为我遇到了与 Ravy 相同的问题,但建议的解决方案对我来说并不合适。
如果您使用带有查询参数的路由路径,则接受的答案不起作用。
这是我使用的解决方案:
//mycomponent.component.ts
class MyComponent {
constructor(public router: Router){
}
}
//mycomponent.component.html
<div *ngIf="router.isActive('/some/route')">
</div>
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
9421 次 |
| 最近记录: |