0

From API I get something like this : processId=22, now i want to pass that in url params, but problem is that i need to pass key and value. How can i paste that whole string as param. Any suggestion?

So what i want to achive is this:

<a *ngIf="menu.refParameter3" [routerLink]="[menu.url ||'/']" [queryParams]="{menu.refParameter3}">test</a>

So in menu.refParamter3 i have processId=22. How can i paste both in url, so that i can have something.com?processId=22

0

1 Answer 1

1

I don't believe there is a way to pass in the key + value string as query parameters. Once you receive the parameter from the api, you could convert it to an object and pass it in to the queryParams input.

// basic conversion code
let queryParams = {};
let split = menu.refParameter3.split('=');
queryParams[split[0]] = split[1];
menu.queryParams = queryParams;

// menu.queryParams = {
//     processId: 22
// }

// html
<a [routerLink]="[menu.url ||'/']" [queryParams]="menu.queryParams">test</a>
Sign up to request clarification or add additional context in comments.

7 Comments

thats fixed value processId:22 i want to avoid that and get key and value from api and pass it to query params
you can make it dynamic based on how your code is set up. Once you receive the key value from the api convert it from a string to the above format
@None I've updated my answer with some basic code that would convert the string to an object
problem is that queryParams not add in url this object processId: "22"
What url do you get?
|

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.