I've stumbled upon this question here by looking for the reason, that a well defined factory is not loaded. Then I wondered about the terms "defined in an angular module".
If I have kind of a service like this:
angular.module('d3', ['underscore'])
.factory('d3', ['$window', 'underscore',
function($window, _) {
if (!_.isObject($window.d3)) {
throw "services.d3: moment library missing!";
} else {
return $window.d3;
}
}
]);
And when I try to load this service in a module like this:
angular.module("widgets.D3Widget", ['underscore'])
.controller("widgets.D3Widget.D3WidgetCtrl", [
"$scope",
"d3",
function(
$scope,
d3
) {
console.log(d3.select('body'));
//work goes here
}
]);
the service is not loaded. I rather get an Angular error like: "Error: [$injector:unpr] Unknown provider: d3Provider <- d3.
I've read the Angular docu about DI, but that didn't help very much.
So what is meant by 'defining the service'? Writing the module d3 seems not to be enough, I need to add it in a second module, like angular.module("widgets.D3Widget", ['underscore', 'd3']), not just in a component of a module (controller, directive, whatever). Is that right?