I am using odata service and i want to create helper service per each entity type, so after getting the metadata i am creating the factory (this is done before angular was bootsrapped)
var serviceName = allTypes[type].shortName + 'RepositoryService';
angular.module('app').factory(serviceName, [function() {
function sayHello() {
console.log('hello');
}
return {
sayHello: sayHello
};
}]);
and I am trying to consume it in another controller
sensorService = $injector.get('CSensorRepositoryService');
and i am getting an error
Error: [$injector:unpr] Unknown provider: CSensorRepositoryServiceProvider <- CSensorRepositoryService
when iterated over all the available factories I saw that this factory exits
var mod = angular.module('app');
for (var id in mod._invokeQueue) {
if ((mod._invokeQueue[id])[1] === 'factory') {
console.log( id + " " + ((mod._invokeQueue[id])[2])[0]);
}
}
and when I tried to take factory which was "hard coded" all was ok what I am doing wrong?
You can do this by exposing the providers from app.config so...
var app = angular.module('app',[]);
app.config(function($provide){
app.register =
{
factory: $provide.factory,
service: $provide.service,
constant: $provide.constant
};
});
Then at a later time...
app.register.factory('myFactory',function(){...});
I'd just be sure this doesn't happen someplace where it could occur repeatedly
This is the same concept as presented here.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With