Search code examples
javascriptangularjsangular-ui-routerui-sref

Angular ui-sref, param removes spaces? Workaround for it?


I have an anchor tag:

<a ui-sref="view({id:{{ id }}})" data-toggle="tooltip" data-placement="top" title="View Details"><i class="fa fa-search-plus fa-2x icon-color"></i></a> 

The id value I am getting here is "ID - 100"(including the spaces). When I click on this link, the URL it gets moved to is "view/-100". Notice that it has removed the text characters before the "-" and the spaces as well.

This results in the incorrect data being passed. Not exactly sure how to pass this value? (Hoping to find the solution in a ui-sref. Not using ng-click ).

Thanks in advance.

JSFiddle: http://jsfiddle.net/6mpbfk3c/

Note that in console you will see this error:

"NetworkError: 404 Not Found - http://jsonplaceholder.typicode.com/posts/-100"


Solution

  • Have a look, it must be helpful. fiddle

    <button ui-sref="posts.details.about({postId: 'USL - 100'})">Load Post Details About</button><br/>