【发布时间】:2017-09-23 16:34:01
【问题描述】:
我们可以通过HTML来设置路由参数:
<a [routerLink] = "['/api/foo/', id]"/>
我知道我们可以通过处理typescript中的事件来读取路由参数:
import {OnInit, OnDestroy, Component} from '@angular/core';
@Component({...})
export class MyComponent implements OnInit{
constructor(private activatedRoute: ActivatedRoute) {}
ngOnInit() {
// subscribe to router event
this.activatedRoute.params.subscribe((params: Params) => {
let Id = params['id'];
console.log(Id);
});
}
}
但是,有没有办法在 HTML 中读取路由参数,而不是在 TypeScript 组件中?
我想以如下方式使用:
<a href="api/foo/[routerLink]"/>
【问题讨论】:
-
是什么阻止您阅读组件中的参数?
-
告诉我你在 HTML 的什么地方使用它?
-
你不能这样用,就是不行
-
@RomanC 这是我的问题。有没有办法在 HTML 中使用
router。 -
@downvoter 投反对票的理由是什么?
标签: javascript angular typescript angular2-routing