37

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")
};
3
  • Should it be {go('..')} . teh angularjs docs say <ANY ng-click="{expression}"> Commented Mar 8, 2013 at 6:34
  • hm.. that's not working for me either... Commented Mar 8, 2013 at 6:36
  • Does ng-click="go('/alert_instance/' + ai.alert_instancne_id)" work? Commented Mar 8, 2013 at 9:24

1 Answer 1

90

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;
  //...
};
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.