1

Is there any kind of equivalent to ui-router's ui-sref?

As of now all my ng-href's are hard-coded string literals, ex;

<a ng-href="#/users/{{user.id}}/{{user.fullname}}"></a>

which makes me shiver whenever I see it.

Are there any built-in functionality in ngRoute that handles this, or do I have to make my own service? Are there any other solutions?

William Boman
  • 2,079
  • 5
  • 26
  • 39

1 Answers1

1

Yes, that is shiver worthy.

According to the ng-href documentation, they also expect you to hard code all params as strings. Ui-router supports the object param paradigm out of the box with the ui-sref directive. (Here's an article for getting started with ui-router since you asked if there are alternatives).

If you do not want to switch to ui-router but you are willing to use query string params, something like this may work: https://stackoverflow.com/a/21082131/3914443. It's an angular filter which simply turns your object into a query string for the next view/controller route.

Community
  • 1
  • 1
lasergoat
  • 11
  • 1
  • `ngRoute` is way too integrated in my app at the moment to revert it :(. I actually started with `ui-router` but ditched it because they didn't support optional parameters. I'm gonna try and make a provider which'll act as a funnel when setting up app routes. This way I can store & access data about a route from anywhere within my app, and even make a method that "generates" urls.. somehow. I'll see how it goes. – William Boman Aug 06 '14 at 13:54