Search code examples
javascriptangularjsroutesangular-ui-routerangularjs-routing

How can I construct an AngularJS state parameter in the view by concatenation?


Using the AngularJD ui-router, I have defined a state myState that takes 3 parameters: stateParam1, stateParam2 and stateParam3.

In my view the variables var1 and var2 are already defined. I pass them in as stateParam1 and stateParam2 respectively. That works. But for stateParam3, I want to send in the concatenation of the first two fields. But how do I do it? How can I concatenate var1 and var2 into a third variable that I send in as stateParam3?

<a ui-sref="myState({'stateParam1': var1, 'stateParam2': var2, 'stateParam3': WHAT_GOES_HERE? })">

Solution

  • It would be simple string concatenation of those variables like var1 + var2

    ui-sref="myState({'stateParam1': var1, 'stateParam2': var2, 'stateParam3': var1 + var2 })">