【发布时间】:2017-03-14 21:52:50
【问题描述】:
所以我有两个组件,HomePageComponent 和 StudentsViewComponent。在 HomePageComponent 我有一个输入标签:
<input type="text" #careerObj class="modules" placeholder="Career Objective ( software engineer)">
<button class="submit" routerLinkActive="active" [routerLink]="['/students', careerObj.value ]">Search</button>
我想使用参数将此输入的值传递给 studentsViewComponent。
它重定向到正确的路由,但参数为空。该值始终为空,我不知道为什么。
这是我的路线:
{
path: 'students/:searchQuery',
component: StudentsViewComponent
},
ngOnInit() {
this.activatedRoute.params.subscribe((params: Params) => {
console.log(params);
});
}
不确定为什么参数为空。
请帮忙
【问题讨论】:
-
您提供的代码示例没有任何问题。我复制了您的示例并且它有效...尝试使用
Select(val: string) { this.router.navigate(['/ad/' + val]); }从您的组件更改路由以查找问题 -
您在重定向后的 url 中看到查询?
-
重定向时没有报错,但是查询为空,如
""@BabarBilal -
谢谢,您的解决方案有效,但我对您的解决方案有效的原因感到非常困惑。为什么我的方法行不通?您可以完整地提供您的答案,以便我接受您的解决方案。 @Brivvirs
标签: angular typescript angular2-routing angular2-router routeparams