Angular 6 passing in parameters into URL

Vlad Bogza

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

Maarti

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'];
});

この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。

侵害の場合は、連絡してください[email protected]

編集
0

コメントを追加

0

関連記事

分類Dev

Iframe not passing url parameters

分類Dev

Passing URL parameters in asp.net

分類Dev

AngularJS: Navigate passing GET parameters in URL

分類Dev

Passing parameters to Angular UI router template

分類Dev

Angular JS - Retrieve URL parameters

分類Dev

passing parameters through URL to action using Struts2 taglib

分類Dev

Angular 2 passing parameters to constructor throws DI exception

分類Dev

Angular 6 removes query string from url

分類Dev

Angular 6 convert group form to get request query parameters

分類Dev

Passing parameters to middleware in Laravel

分類Dev

Passing parameters to a custom URI

分類Dev

Passing parameters to AngularJS $timeout

分類Dev

Passing parameters to a custom URI

分類Dev

Passing LINQ expressions as parameters

分類Dev

Passing parameters to jest function

分類Dev

Passing parameters to a OPENQUERY

分類Dev

passing BlocProvider with class parameters

分類Dev

Passing parameters to a react component

分類Dev

Error with passing parameters

分類Dev

Maple passing parameters by reference

分類Dev

How to keep uppercase when passing parameters from url into whatsapp api web?

分類Dev

Parameters in URL using Angular's UI-Router, issue with .otherwise

分類Dev

Golang: Passing structs as parameters of a function

分類Dev

Passing additional parameters to MapStruct mapper

分類Dev

Passing parameters in rmarkdown to the text or headings

分類Dev

Passing parameters to scalameta paradise macro

分類Dev

Passing parameters in java script function ?

分類Dev

how to change http req url using angular 6 interceptor

分類Dev

Passing URL in a function

Related 関連記事

ホットタグ

アーカイブ