ngCordova icon indicating copy to clipboard operation
ngCordova copied to clipboard

how to cordova plugins adding

Open mohansolai opened this issue 7 years ago • 3 comments

How to Camera and battery status plugins added and same code or include controller pls explain and code

mohansolai avatar Nov 19 '17 02:11 mohansolai

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!

NavCore avatar Nov 19 '17 11:11 NavCore

How to add it in angular 4 project?

anireddysai avatar Nov 24 '17 13:11 anireddysai

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.

NavCore avatar Jan 08 '18 22:01 NavCore