I'm a beginner with Angular 2 and I'm seeking advice on how to pass multiple parameters to Angular's service module. For instance, here is the first parameter I'm passing to the service through the router link.
In the home-component.html file:
<a href="#" [routerLink]="['/product', product.slug]">
This link is connected to the route defined in app.routes.ts which loads the ProductOverviewComponent.
const appRoutes: Routes = [
{ path: 'product/:slug', component: ProductOverviewComponent, canActivate: [AuthGuard] },
{ path: 'login', component: LoginComponent },
{ path: '', component: HomeComponent, canActivate: [AuthGuard] },
// Redirect to home if no matching route
{ path: '**', redirectTo: '' }
];
The product-overview.component.ts file utilizes the getProductOverview()
method.
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);
});
}
This method then calls the getProductOverview function from product-overview.service.ts
getProductOverview(slug: string): Observable<Course> {
let product$ = this.http
.get(`${this.baseUrl}${slug}/` , options)
.map((response: Response) => response.json());
}
My inquiry revolves around how to include a second route parameter in the getProductDetail function?
For example:
getProductDetail(slug: string): Observable<Course> {
let productDetail$ = this.http
.get(`${this.baseUrl}${slug}/${slug2}` , options)
.map((response: Response) => response.json());
}
Any tips or suggestions are greatly welcomed.