Can someone assist me with a function I am trying to create in my service? I want the function to use FileReader to read a small image file and return the result in a promise to my controller. The issue is that while the file reaches the service without any problem, it only logs a blank line when it gets to the controller. I believe the problem lies within how I am handling promises in this situation. Any ideas on what I am doing wrong?
Here is the code for the service function:
this.fileRead = function(file) {
var deferred = $q.defer();
var reader = new FileReader();
reader.readAsDataURL(file);
deferred.resolve(reader.result);
return deferred.promise;
};
And here is the code for the controller function:
$scope.onFileSelect = function($files) {
MyService.fileRead($files[0])
.then(function(result) {
console.log(result);
});
};