【发布时间】:2015-07-14 21:29:17
【问题描述】:
我在自定义指令的模板中使用ng-repeat,如下所示:
<li ng-repeat="image in images">
<img ng-src="{{image.url}}" ng-click="togglePhoto({{$index}})">
</li>
当呈现在页面上时,源看起来像
<li ng-repeat="image in images" class="ng-scope">
<img ng-src="http://example.com/example.jpg" ng-click="togglePhoto(1)" src="http://example.com/example.jpg">
</li>
我的指令中定义了函数togglePhoto。如果没有传递{{index}} 参数,它就可以工作并调用该函数。使用索引,它不会触发。
togglePhoto函数中如何获取点击照片的索引?
【问题讨论】:
-
togglePhoto(x)是如何定义的?
标签: angularjs angularjs-directive