-2
我想說明一個簡單的例子無法綁定在NG-重複單擊事件
var app =angular.module('myApp',[]);
app.directive('callapi', function($compile, $rootScope) {
return {
restrict: 'A',
replace: false,
terminal: true,
priority: 1000,
compile: function compile(element, attrs) {
element.bind('click', function() {
alert('clicked');
});
return {
pre: function preLink(scope, iElement, iAttrs, controller) {},
post: function postLink(scope, iElement, iAttrs, controller) {
$compile(iElement)(scope);
}
};
}
};
});
app.controller('myController',function($scope){
\t $scope.simpleList = [1,2,3]
})
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
<div ng-app=myApp>
<div ng-controller='myController'>
<table>
<button callapi='api/user'>outerNgRepeat</button>
<tr ng-repeat='r in simpleList'>
<td>r</td>
<td>r</td>
<td><button callapi='api/user'>innerNgRepeat</button></td>
</tr>
</table>
</div>
</div>
我不得不嘗試綁定單擊事件在指令中的元素上,但它在ng-repeat時不起作用。 如何綁定點擊ng-repeat中的元素?
的截圖代碼不適合問一個問題 – Phil
請提供代碼,而不是截圖 – Nitheesh
對不起這個,但我在jsfiddle代碼中得到了另一個問題.... –