2013-03-05 24 views
3

我试图用一个标签是这样的:

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

然而,当我点击标签没有任何反应。

奇怪的是,如果我有硬编码的价值,就像这样:

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

它按预期工作。

截图DOM的:

enter image description here

为什么会变成这样?我怎么能解决这个问题?

+0

你可以制作一个JsFiddle来证明这一点吗? – Marc 2013-03-05 03:24:35

+3

你可以试试'$ location.path('/ restaurant /'+ restaurant.id)'?请参阅http://stackoverflow.com/questions/14596235/angularjs-ng-click-not-invoked-with-index-used – 2013-03-05 03:26:16

+0

哦!这样可行!如果你想回答一个问题,我会接受它。谢谢。 – marclar 2013-03-05 03:28:29

回答

0

希望这有助于!

$scope.doTheNeedful = function(country){ 
     var newPath = "home/"; 
     newPath += country; 
     $location.path(newPath); 
    }