Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ng-click not setting $location.path() when path is dynamic

Tags:

angularjs

I'm trying to use a tag like this:

<a ng-click="$location.path('/restaurant/{{restaurant._id}}')">{{restaurant.name}}</a>

However, nothing happens when I click the tag.

Oddly, if I hard-code the value there, like this:

<a ng-click="$location.path('/restaurant/512ad624b67fe1f446709331')">{{restaurant.name}}</a>

it works as expected.

Screenshot of the DOM:

enter image description here

Why would this be? How could I work around this?

like image 259
marclar Avatar asked Nov 24 '25 14:11

marclar


1 Answers

From AngularJS ng-click not invoked with {{$index}} used, you are able to use the variable directly, without braces.

I.e.

<a ng-click="$location.path('/restaurant/' + restaurant._id)">{{restaurant.name}}</a>
like image 114
Alex Osborn Avatar answered Nov 28 '25 09:11

Alex Osborn