イベントをバインドすることはできましたが、一部のイベントが を使用して機能しないことがすぐにわかりましたangular.element.bind()
。たとえば、イベントの場合、構文click
を使用する必要がありました。Event.add()
これは次のようになります。
angular.module('myApp', []).config(function(){
Event.modifyEventListener = true;
Event.modifySelectors = true;
}).controller('SomeCtrl', function($scope){
$scope.eventType = "";
}).directive('foo', function($log){
return {
link: function(scope, elm, attr){
// here it is using the 'bind' syntax
elm.bind('mousedown mouseup mouseenter mouseleave', function(evt){
$log.debug(evt);
scope.eventType = evt.type;
scope.$apply();
});
// here it is using Event.add
Event.add(elm[0], 'click', function(evt, context) {
$log.debug(context);
scope.gesture = context.gesture + ', ' + context.pointerType;
scope.$apply();
});
}
};
});
ここでデモを見ることができます: http://plnkr.co/edit/FLMckw?p=preview