Advertisement
Guest User

Untitled

a guest
Jan 3rd, 2016
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //Form controller
  2.  
  3. $scope.fromCamera = function () {
  4.     var options =   {
  5.       quality: 50,
  6.       destinationType: navigator.camera.DestinationType.FILE_URI,
  7.       sourceType: navigator.camera.PictureSourceType.CAMERA,
  8.       encodingType: 0
  9.       };
  10.  
  11.  
  12.     Camera.getPicture(options).then(function(res) {
  13.       console.log(res);
  14.       return res;
  15.     }, function(err) {
  16.       console.log(err);
  17.     });
  18.   }
  19.  
  20.   $scope.fromLibrary = function () {
  21.     var options =   {
  22.       quality: 50,
  23.       destinationType: navigator.camera.DestinationType.FILE_URI,
  24.       sourceType: navigator.camera.PictureSourceType.PHOTOLIBRARY,
  25.       encodingType: 0
  26.       };
  27.  
  28.     Camera.getPicture(options).then(function(res) {
  29.       console.log(res);
  30.       return res;
  31.     }, function(err) {
  32.       console.log(err);
  33.     });
  34.  
  35.  
  36.   }
  37.  
  38. //Meal template
  39.  <span style="padding: 5px 0 5px 0;">Image From: </span>
  40.             <button class="button button-icon ion-camera" ng-click="fromCamera()"> Camera </button>
  41.             <button class="button button-icon ion-image" ng-click="fromLibrary()"> Library </button>  
  42.         </label>
  43.  
  44.  
  45. //Services.js
  46. .factory('Camera', ['$q', function($q) {
  47.   return {
  48.     getPicture: function(options) {
  49.       var q = $q.defer();
  50.  
  51.       navigator.camera.getPicture(function(result) {
  52.         q.resolve(result);
  53.       }, function(err) {
  54.         q.reject(err);
  55.       }, options);
  56.  
  57.       return q.promise;
  58.     }
  59.   }
  60. }])
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement