Javascript AngularJS-如何绑定到指令中的ngRepeat元素

Javascript AngularJS-如何绑定到指令中的ngRepeat元素,javascript,web,angularjs,closures,directive,Javascript,Web,Angularjs,Closures,Directive,在我的指令中,我有一个带有ng repeat的模板 ...return { template:'<div id="wrapper"><ul><li ng-repeat="item in items">{{item.name}}</li></ul></div>', compile:function (tElement, tAttrs) { return function (sco

在我的指令中,我有一个带有ng repeat的模板

 ...return {
       template:'<div id="wrapper"><ul><li ng-repeat="item in items">{{item.name}}</li></ul></div>',
       compile:function (tElement, tAttrs) {

        return function (scope, iElement, iAttrs) {
              //bind item mouse event to a closure function
        }
    }
    }...
…返回{
模板:“
  • {{item.name}
”, 编译:函数(远程通讯、tAttrs){ 返回功能(范围、IELENT、iAttrs){ //将项鼠标事件绑定到闭包函数 } } }...

我想用指令中的函数绑定中继器的每个元素,最好的方法是什么?

您需要创建隔离的作用域并将项传递给指令,方法是将
作用域:{items:'=}
添加到指令定义对象,然后将处理程序添加到每个项:

<span ng-click='clicked(item)'>{{item.name}}<span>
并将其用作

scope.clicked = function(item) { .. Do thmthng with item...};