Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/perl/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Angular2-将参数传递到指定出口_Angular_Parameters_Routing - Fatal编程技术网

Angular2-将参数传递到指定出口

Angular2-将参数传递到指定出口,angular,parameters,routing,Angular,Parameters,Routing,我需要将参数从默认出口传递到命名出口。通过之后,我得到的只是“未定义”。这是我的密码 [routerLink]="['', { outlets: { secondOutlet: 'messages' }, name: this.userName, lastName: this.userLastName}]" 我收到了这封信 this.route$ = this.route.params.subscribe((params: Params) => { this.name=

我需要将参数从默认出口传递到命名出口。通过之后,我得到的只是“未定义”。这是我的密码

[routerLink]="['', { outlets: { secondOutlet: 'messages' }, name: this.userName, lastName: this.userLastName}]"
我收到了这封信

    this.route$ = this.route.params.subscribe((params: Params) => {
     this.name= params['name'];
     this.lastName= params['lastName'];
   });
我没有得到错误,但在控制台中,我得到的只是未定义的错误。
如果路由在同一个插座上,我可以将参数发送到路由,但我不知道如何将参数从一个插座发送到另一个插座。

嗨,你能看看这篇文章吗

我希望它能对你有所帮助

  [routerLink]="['', { outlets: { secondOutlet: ['messages', this.userName ] } }]"
和路线内规范

Routes = [
{
    path: 'messages/:username',
    component: AccountsEditComponent,
    outlet: 'secondOutlet'
  }
]
它是这样工作的。 发送如下参数:

[routerLink]="['', { outlets: { secondOutlet: ['messages', this.username] } }]"
在routes中,按如下方式设置组件

Routes = [
{
    path: 'messages/:username',
    component: AccountsEditComponent,
    outlet: 'secondOutlet'
  }
]

感谢你们的努力,但最好下次把它放在评论中,这样做了,我可以在URL中看到参数。但是当我收到它们时,我仍然没有定义。useName:string;专用路线$:订阅;this.route$=this.route.params.subscribe(params=>{this.userName=params['userName'];});是的,但是当收到参数时,它们显示为“未定义”。这是我的第一篇文章。我一直在使用它,但现在有些东西不起作用了。@BrS,您可以像这样将FirstChild添加到路由中。route$=this.route.FirstChild.params.subscribe(params=>{this.userName=params['userName'];});我可以看到您已经标记了答案,但没有明确的解释您的代码最初是怎么回事?@PraveenRawat错误的是发送参数和设置路由的方式,解释了这个答案与已接受的答案有何不同?