我正在尝试使用这样的标签:

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

但是,当我单击标签时没有任何 react 。

奇怪的是,如果我对那里的值进行硬编码,如下所示:
<a ng-click="$location.path('/restaurant/512ad624b67fe1f446709331')">{{restaurant.name}}</a>

它按预期工作。

DOM 的屏幕截图:

为什么会这样?我该如何解决这个问题?

最佳答案

AngularJS ng-click not invoked with {{$index}} used ,您可以直接使用变量,无需大括号。

IE。

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

关于angularjs - 当路径是动态的时,ng-click 不设置 $location.path(),我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/15215219/

10-12 15:19