2
我想編寫該指令沒有jQuery的。我怎麼可以這樣寫指令,而無需使用element.on - 不使用jQuery
本SO question我試圖Inpired擺脫在不需要它的jQuery或在那裏我可以做另一種方式。 。 。
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
})
});
}
};
});
謝謝!
使用elm.bind而不是elm.on – ganaraj 2013-04-29 14:26:43
@ganaraj將其設置爲問題的答案,它發揮了訣竅! – Arcayne 2013-04-29 14:43:19