简体   繁体   中英

AngularJS - {{$index}} within onclick

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!

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

Docs/examples:

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM