So I have an angular app that currently has a route such "urlname/stockdata". I would like to be able to pass in a stock symbol into that url such as "urlname/stockdata/AAPL". My app is making a call to a third party API with that symbol. Do you guys have any advice on how I can do that. Any help is appreciated. Thanks
You can declare a route with parameters like this:
export const routes: Routes = [
{ path: 'urlname/stockdata/:id', component: MyComp}
];
Create a link in the template:
<a [routerLink]="['/urlname/stockdata', id]">MyLink</a>
Or navigate from the .ts
:
this.router.navigate(['/urlname/stockdata', id]);
Then you can read it with:
constructor(private route: ActivatedRoute) {}
this.route.params.subscribe(params => {
this.id = params['id'];
});
TS File
const routes: Routes = [{
path: '',
children: [{
path: 'plans/:id',
component: PlanListComponent,
canActivateChild: [AuthGuard]
}]
}];
HTML
<a class="dropdown-item" (click)="viewDetails(product.id)">View Detail</a>
TS
viewDetails (productId) {
this.router.navigate([ BASE_URL +"/plans/" + productId]);
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With