2016-09-03 11 views
0

私は角度2を初めて使用しました。角度のサービスモジュールに複数のパラメータを渡す方法についてのご意見をお待ちしております。たとえば、ルータのリンクを介してサービスに渡している最初のパラメータがここにあります。2番目のサービスモジュールに2番目の経路パラメータを渡すにはどうすればよいですか?

ホームcomponent.html app.routes.ts以下に定義されたルートにマッピングされ、ProductOverviewComponentをロードさ

<a href="#" [routerLink]="['/product', product.slug]"> 

const appRoutes: Routes = [ 
{ path: 'product/:slug', component: ProductOverviewComponent, canActivate: [AuthGuard] }, 
{ path: 'login', component: LoginComponent }, 
{ path: '', component: HomeComponent, canActivate: [AuthGuard] }, 

// otherwise redirect to home 
{ path: '**', redirectTo: '' } 
]; 

product-overview.component.tsはgetProductOverview()メソッドを呼び出します。製品-overview.service.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); 
    }); 
} 

getProductOverview(slug: string): Observable<Course> { 
    let product$ = this.http 
     .get(`${this.baseUrl}${slug}/` , options) 
     .map((response: Response) => response.json()); 
} 

私の質問は、私は機能getProductDetailに第2の経路パラメータを渡す方法ですか?例えば

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

任意の入力がはるかに高く評価されています。

答えて

0

あなたはこのように、ルーティングれている必要があります。それはすべき

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

そして作品を!

+0

@daveは動作しますか? –

+0

はい、それは新しいコンポーネントを読み込んでくれてありがとう!私はフォローアップの質問があります! – Dave

+0

パーフェクト@dave私は答えに何の検証も見なかったので私は尋ねました、私は新しい質問をチェックします! –

関連する問題