AngularJS - onclick中的{{$ index}}

时间:2013-11-14 20:58:55

标签: javascript html html5 angularjs

我正在尝试从onclick中的ng-repeat编译{{$ index}}。安装程序看起来像这样。

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

除此之外,我收到了一个控制台错误,而不是{{$ index}}编译。

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}});">

我做错了什么?任何帮助表示赞赏!

1 个答案:

答案 0 :(得分:7)

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

文档/例子: