I have a cross platform app built using Monaca and AngularJS. The app uses the Camera plugin that allows users to take photos.
A have a function that takes the pictures, and in that function I want to return a few values when the photo is successfully captured.
Below is my method that calls the takePicture() function, along with trying to access the returned values. The 2 functions below are called from different Controllers/Services as well.
Controller
// Take photo
$scope.takePicture = function () {
var test = Photo.takePicture();
alert("photoCaptured: " + test.photoCaptured + "\nphotoName" + test.photoName); // Error here
};
Below is the takePicture() function that fires the Camera and returns the values at the onSuccess callback
Service
// Get the main app.js module
var photo = angular.module("photo", []);
photo.service("Photo", function () {
var myFunctions = {
// Take picture
takePicture: function () {
var onSuccess = function (imageURI) {
var photoCaptured, photoName;
return { photoCaptured: true, photoName: imageURI } // Should return multiple values
}
var onFail = function (error) {
alert("AN ERROR HAS OCCURED" + "\nPhoto capture failed." + error);
}
var options = { quality: 50, destinationType: Camera.DestinationType.FILE_URI};
navigator.camera.getPicture(onSuccess, onFail, options);
},
}
return myFunctions;
});
However, the test throws error Cannot read property 'photoCaptured' of undefined.
How do I access the values returned from the onSuccess callback?