问题:
如何正确地从批准元素中var trapfocus()
ParentCtrl
到console.log(el)
?
HTML
<div ng-controller="ParentCtrl">
<div ng-repeat="tab in tabs" modaltab="trapfocus($event)"></div>
</div>
JS:
.directive('modaltab', function() {
return function(scope, element, attrs) {
element.bind("keydown keypress", function(event) {
if(event.which === 9) {
scope.$apply(function(){
scope.$eval(attrs.modaltab, {'event': event});
});
});
};
})
父Ctrl
.controller('ParentCtrl', function(){
var trapfocus = function(evt, el){console.log(el)};
$scope.tabs = [1,2,3,4];
});
答案 0 :(得分:1)
无需$eval
。在指令的范围内声明此属性:
scope: {
modaltab: "&"
}
然后,从链接函数中调用它:
modaltab({'$event': event});