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?
Because it makes it a lot easier to use Cordova plugins when you are using angularjs.
With ngCordova, instead of calling Cordova plugins directly and having to figure out the proper object or plugin name, or to check if the plugin is actually installed, you can just call a simple AngularJS service like this:
you can check out the details here, http://blog.ionic.io/ng-cordova/