0

I would like to set the query parameter name dynamically.

this.router.navigate([alternativeRedirect],{ queryParams: { supportContractId: p },})

Is it possible to set supportContractId dynamically:

let parameterName = 'supportContractId'

this.router.navigate([alternativeRedirect],{ queryParams: { parameterName: p },})

2
  • 1
    If I have understood your question right, you basically want to create queryParams object with dynamic keys? Commented Sep 8, 2021 at 15:11
  • Have you already tried something like this (second option) Commented Sep 8, 2021 at 15:13

2 Answers 2

2

You can define the params object beforehand and set the properties dynamically using the property accessor (aka bracket notation). It would be something along those lines:

let params = {};
params[parameterName] = p;
this.router.navigate([alternativeRedirect],{ queryParams: params})
Sign up to request clarification or add additional context in comments.

Comments

1

According to the ECMAScript2015 language specification, you can create objects with computed keys.

Therefore you can directly do the following,

let parameterName = 'supportContractID'
this.router.navigate([alternativeRedirect],{ queryParams: { [parameterName]: value })

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.