@madibaion wrote:
In my projec app ,i need to reuse the camera module , it being called 5 times in different controllers ,
i need a way to reuse the function around, and allow configuration on the options object
here is what i came up with
javascript
(function() { angular.module('app') .factory('MediaService', MediaServiceFn); function MediaServiceFn($q) { var recordAudio = function() {}; var takePicture = function(sourceType) { var q = $q.defer(); this.sourceType = sourceType; _picker = false; if (this.sourceType === 'camera') { _picker = true; } var camera = something; var photoLibary = something; var options = { quality: 50, allowEdit: true, correctOrientation: false, targetWidth: 640, targetHeight: 1080, destinationType: Camera.DestinationType.FILE_URI, sourceType: picker ? camera : photoLibary, encodingType: Camera.EncodingType.JPEG, saveToPhotoAlbum: false }; $cordovaCamera.getPicture(options).then(function(imageData) { $q.resolve(imageData); }, function(err) { $q.reject(err); }); return d.promise; }; return { takePicture: takePicture }; } }());
and my controller
angular.module(app) .controller('AppCtrl', AppCtrl); function AppCtrl($scope, MediaService) { $scope.choose = { 'choice': 'camera' }; $scope.getPicture = MediaService.takePicture($choose.choice) .then(function(imageData) { // image data here }, function(error) { // error handler }); }
any advice on the better way to handle this scenario
Posts: 1
Participants: 1