本文介绍了如何在路由器链接上* ngIf?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我需要在某些页面上显示一些内容,而在其他页面上则不应该显示.我该如何实现?没用
I need to show some content on certain page, in other pages it shouldn't be visible. How do I achieve it ? it doesn't work
*ngIf="[routerLink]="['/home']"
推荐答案
您可以从'@ angular/router'注入Router并获取当前所在的路线.
You can inject Router from '@angular/router' and get the current route you're on.
例如:
// mycomponent.component.ts
class MyComponent {
constructor(public router: Router) {
}
}
// mycomponent.component.html
<div *ngIf="router.url === '/some/route'">
</div>
这篇关于如何在路由器链接上* ngIf?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!