Ionic - Cordova Camera

The Cordova camera module uses the nearby camera for taking film or procuring pictures from the image gallery.

Using Camera

Open your assignment root coordinator in electronic correspondence, by then trade and present the Cordova camera module with the subsequent command.

C:\Users\Username\Desktop\MyApp> cordova module incorporate org.apache.cordova.camera 

Now, we'll produce an organization for using a camera module. we'll use the AngularJS present day plant and certification object $q that must be implanted to the mechanical plant.

services.js Code

.factory('Camera', function($q) { 

return { 

getPicture: function(options) { 

var q = $q.defer(); 

navigator.camera.getPicture(function(result) { 


}, function(err) { 


}, options); 

return q.promise; 




To use this organization in the application, we need to inject it to a controller as a dependence. Cordova camera API gives the getPicture methodology, which is used for taking photos using a neighborhood camera.

The neighborhood camera settings can be likewise modified by passing the decisions parameter to the takePicture work. Copy the recently referenced code test to your controller to trigger this direct. It will open the camera application and return a triumph callback work with the image data or error callback work with a bungle message. We will in like manner require two gets that will call the limits we are going to make and we need to show the image on the screen.


<button class = "button" ng-click = "takePicture()">Take Picture</button> 

<button class = "button" ng-click = "getPicture()">Open Gallery</button> 

<img ng-src = "{{user.picture}}">

Controller Code

.controller('MyCtrl', function($scope, Camera) { 

$scope.takePicture = function (options) { 

var alternatives = { 

quality : 75, 

targetWidth: 200, 

targetHeight: 200, 

sourceType: 1 


Camera.getPicture(options).then(function(imageData) { 

$scope.picture = imageData;; 

}, function(err) { 





The yield will look as appeared in the accompanying screenshot.

Ionic Cordova Camera

If you might want to utilize pictures from your exhibition, the sole issue you might want to change is that the sourceType procedure from your decisions parameter. this alteration can open an exchange popup as opposed to camera and license you to choose the picture you might want from the device.

You can see the consequent code, wherever the sourceType probability is adjusted to zero. Presently, after you spigot the second catch, it'll open the document menu from the device..

Controller Code

.controller('MyCtrl', function($scope, Camera) { 

$scope.getPicture = function (options) { 

var alternatives = { 

quality : 75, 

targetWidth: Ionic Cordova Camera Image

Welookups is optimized for learning.© 2018 kumar aditya singh .
All Right Reserved and you agree to have read and accepted our term and condition.
All Rights Reserved.