I am trying to write a very simple function in my service that will create a FileReader, read the small image file I send it and return this result in a promise to my controller. The file gets to my service just fine. It gets to my controller and logs just a blank line. I assume I am messing up the promise part of this somehow. Where am I going wrong there?
Service funtion --
this.fileRead = function(file) {
var deferred = $q.defer();
var reader = new FileReader();
reader.readAsDataURL(file);
deferred.resolve(reader.result);
return deferred.promise;
};
Controller function --
$scope.onFileSelect = function($files) {
MyService.fileRead($files[0])
.then(function(result) {
console.log(result);
});
};