I am using ionic (new user) and I need some plugins. I am having trouble why I would want to use ngcordova instead of using the cordova plugin directly using the following steps?
For instance to be able to capture video I could use the ngcordova plugin:
$ cordova plugin add cordova-plugin-media-capture
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
module.controller('MyCtrl', function($scope, $cordovaCapture) {
$scope.captureVideo = function() {
var options = { limit: 3, duration: 15 };
$cordovaCapture.captureVideo(options).then(function(videoData) {
// Success! Video data is here
}, function(err) {
// An error occurred. Show a message to the user
});
}
});
Or I can use the cordova plugin directly:
$ cordova plugin add cordova-plugin-media-capture
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
document.addEventListener("deviceready", onDeviceReady, false);
function onDeviceReady() {
navigator.device.capture.captureVideo(
CaptureCB captureSuccess, CaptureErrorCB captureError,[CaptureVideoOptions options]
);
}
I am then trying to understand what is the benefit of using ngcordova over the plugin directly? Would the plugin directly not be better as then you can always have the latest code if you need it and there is no abstraction?
(Source)
So, without ngCordova, you're accessing the Cordova library directly via "plain JS". ngCordova wraps the library up in an Angular-friendly way.
You could argue that if you're using raw Cordova (not ng-cordova) with Angular, you should wrap your Cordova calls in a service. This is essentially "reinventing the wheel" since ng-cordova has been provided for this exact purpose. :)