Stack Overflow is a community of 4.7 million programmers, just like you, helping each other.

Join them; it only takes a minute:

Sign up
Join the Stack Overflow community to:
  1. Ask programming questions
  2. Answer and help your peers
  3. Get recognized for your expertise

I'm attempting to compile {{$index}} from a ng-repeat inside an onclick. Setup looks like this.

<div ng-repeat="stuff in things" >
<a href="#" onclick="superDuperFunction({{$index}});">Foo</a>
</div>

Except, I'm getting a console error instead of it {{$index}} compiling.

Error: [$compile:nodomevents] http://errors.angularjs.org/undefined/$compile/nodomevents
    at Error (<anonymous>)
    at http://localhost:3000/lib/angular.min.js:6:453
    at pre (http://localhost:3000/lib/angular.min.js:57:54)
    at S (http://localhost:3000/lib/angular.min.js:49:122)
    at h (http://localhost:3000/lib/angular.min.js:43:59)
    at h (http://localhost:3000/lib/angular.min.js:43:76)
    at h (http://localhost:3000/lib/angular.min.js:43:76)
    at h (http://localhost:3000/lib/angular.min.js:43:76)
    at http://localhost:3000/lib/angular.min.js:42:114
    at http://localhost:3000/lib/angular.min.js:183:186 <a href="#" onclick="superDuperFunction({{$index}});">

What am I doing wrong? Any help is appreciated!

share|improve this question
    
Why are you using an inline JS handler when you're using Angular? – tymeJV Nov 14 '13 at 21:01
    
Honestly, I'm still learning the ups and downs of Angular. Just couldn't find proper documentation on a situation like this. – Dustin Nov 14 '13 at 21:07
    
ng-click is definitely the way you want to go, then you define the function in the controller such as $scope.myFunc = function(param) { – tymeJV Nov 14 '13 at 21:10
up vote 6 down vote accepted

Try <a href="#" ng-click="superDuperFunction($index)">Foo</a>.

Docs/examples:

share|improve this answer
    
I thought that at first, but it doesn't seem to work. I attempted to use ng-click with a function that has no parameters does work with onclick, but doesn't work with ng-click. – Dustin Nov 14 '13 at 21:08
    
Make sure that superDuperFunctionis defined in your controller i.e. $scope.superDuperFunction = function(index) { .... – Heikki Nov 14 '13 at 21:10

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.