I encountered an issue with an unknown provider error when using a factory and declaring it with an anonymous function:
(function () {
'use strict';
angular.module('app').factory('errorCodeFactory', errorCodeFactory);
function errorCodeFactory() {
var factory = {
getMessage: getMessage
};
return factory;
function getMessage(errorObject) {
return "hi";
};
};
});
Interestingly, when I declare the factory without wrapping it in a function, it works perfectly:
angular.module('app').factory('errorCodeFactory', function() {
var factory = {};
factory.getMessage = function (errorObject) {
return "hi";
};
return factory;
});
It's puzzling why the first example doesn't work while the second one does. I have other factories implemented similarly to the first example and they are functioning correctly. There seems to be something missing in my understanding.