Arcayne Arcayne - 2 months ago 6
AngularJS Question

How can I write this directive without using element.on - not using jquery

I would like to write this directive without jQuery.

Inpired by this SO question I am trying to get rid of jquery where it is not needed or where I can do it another way . . .

MyApp.directive('myCamera', function () {
return {
restrict: 'A',
require: 'ngModel',
link: function(scope, element, attrs, ctrl) {
element.on('click', function() {
navigator.camera.getPicture(function (imageURI)
{
scope.$apply(function() {
ctrl.$setViewValue(imageURI);
});
}, function (err) {
ctrl.$setValidity('error', false);
},
//Options => http://docs.phonegap.com/en/2.6.0/cordova_camera_camera.md.html#Camera
{ quality: 50,
destinationType: Camera.DestinationType.FILE_URI
})
});
}
};
});


Thanks!

Answer

To remove the dependency on JQuery, you need to replace

element.on('click',fn(){});

with

element.bind('click',fn(){});

All the documentation for angular's jquery lite implementation is available under

http://docs.angularjs.org/api/angular.element