Skip to content

Instantly share code, notes, and snippets.

@mlynch
Last active August 29, 2015 14:00
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mlynch/11058080 to your computer and use it in GitHub Desktop.
Save mlynch/11058080 to your computer and use it in GitHub Desktop.
Reusable cordova plugin wrapping service service
angular.module('myApp.services', [])
.factory('Camera', ['$q', function($q) {
return {
getPicture: function() {
var q = $q.defer();
navigator.camera.getPicture(function(imageURI) {
// Do any magic you need
q.resolve(imageURI);
}, function(err) {
q.reject(err);
});
return q.promise;
}
}
}]);
@mlynch
Copy link
Author

mlynch commented Apr 18, 2014

Then, use in your controllers:

controller('MyCtrl', function($scope, Camera) {
  Camera.getPicture().then(function(imageURI) {
  }, function(err) {
  });
});

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment