Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Angularjs ng-click on repeat table row not working

ng-click on the following HTML is not working for me in AngularJS

<tr ng-repeat="ai in alert_instances" ng-click="go('/alert_instance/{{ai.alert_instancne_id}}')">
  <td>{{ai.name}}</td>
  <td>{{ai.desc}}</td>
</tr>

The "go" function in my controller at the moment just has

$scope.go = function (hash) {
  console.log("hi")
};
like image 879
ericbae Avatar asked Mar 08 '13 06:03

ericbae


1 Answers

You are doing it wrong. You shouldn't be using curly braces in Angular directives (ng-click), as this syntax is aimed for templates.

A proper way:

<tr ng-repeat="ai in alert_instances" ng-click="go(ai)">   <td>{{ai.name}}</td>   <td>{{ai.desc}}</td> </tr>  $scope.go = function(ai) {   var hash = '/alert_instance/' + ai.alert_instancne_id;   //... }; 
like image 171
ŁukaszBachman Avatar answered Sep 22 '22 14:09

ŁukaszBachman