[英]Passing parent component data to child via routerLink
I have a parent component that has a this button in the html template: 我有一个父组件,在html模板中有一个这个按钮:
<button class="button" [routerLink]="['/modify-alias-detail']">Next</button>
The above seems to work as I get the edit-alias-detail works!
以上似乎工作,因为我得到edit-alias-detail works!
output. 输出。 But I'd like to pass some data from the parent to the child component so I tried this: 但我想将一些数据从父组件传递给子组件,所以我尝试了这个:
<button class="button" [routerLink]="['/modify-alias-detail', aliasName.value]">Next</button>
I get this error in the developer console: 我在开发者控制台中收到此错误:
EXCEPTION: Uncaught (in promise): Error: Cannot match any routes. URL Segment: 'modify-alias-detail//'
I haven't used routerLinks before and I am rather new to angular 2. 我以前没有使用过routerLinks而且我对angular 2更新。
Any help is appreciate. 任何帮助都很感激。 Thanks! 谢谢!
in such way of navigation you can pass queryParams 在这种导航方式中,您可以传递queryParams
<button class="button" (click)="goToAliasDetails(aliasName.value)">Next</button>
then in .ts 然后在.ts
goToAliasDetails(aliasName: string) {
this.router.navigate(['/modify-alias-detail'], {queryParams: {aliasName}});
}
but at the end your url will look like: /modify-alias-detail?aliasName=.... 但最后你的网址将如下所示:/ modify-alias-detail?aliasName = ....
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.