Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/typescript/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
如何将第二个路由参数传递到angular 2服务模块?_Angular_Typescript_Angular2 Routing - Fatal编程技术网

如何将第二个路由参数传递到angular 2服务模块?

如何将第二个路由参数传递到angular 2服务模块?,angular,typescript,angular2-routing,Angular,Typescript,Angular2 Routing,我是angular 2的新手,希望您能为我介绍如何将多个参数传递给angular的服务模块。例如,这里是我通过路由器链接传递给服务的第一个参数 home-component.html <a href="#" [routerLink]="['/product', product.slug]"> product-overview.component.ts调用getProductOverview()方法 ngOnInit() { this.sub = this.route.param

我是angular 2的新手,希望您能为我介绍如何将多个参数传递给angular的服务模块。例如,这里是我通过路由器链接传递给服务的第一个参数

home-component.html

<a href="#" [routerLink]="['/product', product.slug]">
product-overview.component.ts调用
getProductOverview()
方法

ngOnInit() {
  this.sub = this.route.params.subscribe(params => {
    let slug = params['slug'];
    console.log('getting product with slug: ', slug);
    this.productoverviewservice.getProductOverview(slug)
    .subscribe(p => this.product = p);
  });
}
它从product-overview.service.ts调用getProductOverview方法

getProductOverview(slug: string): Observable<Course> {
    let product$ = this.http
        .get(`${this.baseUrl}${slug}/` , options)
        .map((response: Response) => response.json());
}
getProductOverview(slug:string):可观察{
让产品$=this.http
.get(`${this.baseUrl}${slug}/`,选项)
.map((response:response)=>response.json());
}
我的问题是如何将第二个路由参数传递给函数getProductDetail

例如:

getProductDetail(slug: string): Observable<Course> {
    let productDetail$ = this.http
        .get(`${this.baseUrl}${slug}/${slug2}` , options)
        .map((response: Response) => response.json());
}
getProductDetail(slug:string):可观察{
让productDetail$=this.http
.get(`${this.baseUrl}${slug}/${slug2}`,选项)
.map((response:response)=>response.json());
}

非常感谢您的任何意见

您应该有这样的路由:

{path: 'product/:slug/:slug2', component: ProductOverviewComponent, canActivate: [AuthGuard] }])

它应该是有效的

是的,伙计,谢谢,它加载了新组件!我有一个后续问题!完美@dave我问了,因为我没有看到答案的任何验证,我会检查新问题!只需注意@OctavioGarbarino-path不能以斜杠开头。至少在RC6中,你是对的!我会在“redirectTo:”的地方修复它,我在开始时有斜杠,并且工作正常,可以吗?谢谢@mrgoos!Cool@OctavioGarbarino,在
重定向到
中,也不需要斜杠。我在ng2文档中看到了一个带有斜杠的部分,另一个没有斜杠的部分。在我的代码中,我没有斜杠,它正在工作。
{path: 'product/:slug/:slug2', component: ProductOverviewComponent, canActivate: [AuthGuard] }])