ngCordova
ngCordova copied to clipboard
how to cordova plugins adding
How to Camera and battery status plugins added and same code or include controller pls explain and code
From the ngCordova docs (http://ngcordova.com/docs/plugins/camera/),
you can install camera plugin using:
cordova plugin add cordova-plugin-camera --save
(with --save option plugin will be added to config.xml and ready to be used).
Then you can start using the plugin.
Example of code from the link above:
module.controller('PictureCtrl', function($scope, $cordovaCamera) {
document.addEventListener("deviceready", function () {
var options = {
quality: 50,
destinationType: Camera.DestinationType.DATA_URL,
sourceType: Camera.PictureSourceType.CAMERA,
allowEdit: true,
encodingType: Camera.EncodingType.JPEG,
targetWidth: 100,
targetHeight: 100,
popoverOptions: CameraPopoverOptions,
saveToPhotoAlbum: false,
correctOrientation:true
};
$cordovaCamera.getPicture(options).then(function(imageData) {
var image = document.getElementById('myImage');
image.src = "data:image/jpeg;base64," + imageData;
}, function(err) {
// error
});
}, false);
});
Somewhere in your controller you need to inject $cordovaCamera and the use plugin methods such as .getPicture().
I haven't use this plugin before but that's mostly it.
Good luck!
How to add it in angular 4 project?
Sorry for late reply.
As I wrote in my last reply when you installing plugin using command line interface (cli) and put --save it will automatically save reference to plugin in config.xml. That way cordova will have plugin ready to be used.
Then you can stat using installed plugin anywhere in javascript according to instructions from plugin documentation.