Angular 2 Routerlink *ngIf 带参数
Angular 2 Routerlink *ngIf with Param
我有以下包含参数的路由器链接:
http://localhost:4200/item/1
我将如何着手做一个带参数的 *ngIf....
我尝试了以下
<div *ngIf="router.url === '/item/:item_id'">
</div>
我 运行 这个 *ngIf 的组件是 header 未连接到 itemComponent
的组件
您是否尝试过使用 ActivatedRoute。
导入您的组件
import { ActivatedRoute } from '@angular/router';
然后得到你的 url 值如下..
constructor(private route: ActivatedRoute) {
this.route.params.subscribe(params => {
this.item_id = +params['item_id'];
});
在此之后,您将实现 DOM 视图的逻辑。
我有以下包含参数的路由器链接:
http://localhost:4200/item/1
我将如何着手做一个带参数的 *ngIf.... 我尝试了以下
<div *ngIf="router.url === '/item/:item_id'">
</div>
我 运行 这个 *ngIf 的组件是 header 未连接到 itemComponent
的组件您是否尝试过使用 ActivatedRoute。 导入您的组件
import { ActivatedRoute } from '@angular/router';
然后得到你的 url 值如下..
constructor(private route: ActivatedRoute) {
this.route.params.subscribe(params => {
this.item_id = +params['item_id'];
});
在此之后,您将实现 DOM 视图的逻辑。