ngIf 带路由 [英] ngIf with routing
本文介绍了ngIf 带路由的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我需要帮助弄清楚如何使用 Angular 7 做到这一点:
I need help figuring out how to do this with Angular 7:
IF route = page, THEN SHOW item1 OR item2; else SHOW item0
这是一个视觉效果:
我对这一切都很陌生,我似乎对如何去做感到困惑.
I am fairly new to all this and I seem to get confused with how to go about it.
提前致谢.
推荐答案
在你的组件中
import { Routes, Router } from 'node_modules/@angular/router';
export class YourComponent implements OnInit{
constructor(public router: Router ) {
}
}
在 HTML 中:
<ng-container *ngIf="router.url.includes('route01')">
<p>Item0</p>
</ng-container>
这篇关于ngIf 带路由的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文