我有以下包含参数的路由器链接:
http://localhost:4200/item/1
我将如何使用参数执行 *ngIf... 我尝试了以下方法
<div *ngIf="router.url === '/item/:item_id'">
</div>
我运行的组件 *ngIf 是一个未连接到 itemComponent 的 header 组件
最佳答案
您是否尝试过使用ActivatedRoute。 导入到您的组件中
import { ActivatedRoute } from '@angular/router';
然后获取您的网址值,如下所示..
constructor(private route: ActivatedRoute) {
this.route.params.subscribe(params => {
this.item_id = +params['item_id'];
});
在此之后,您将实现 DOM View 的逻辑。
关于javascript - Angular 2 Routerlink *ngIf 与参数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47749698/