我有一个来自单独模块的工厂,我想为我的模块注入提供程序,但我不断收到未知的提供程序错误。我究竟做错了什么?
我想注入的内容:
var angularSocketIO = angular.module('socketioModule', []);
angularSocketIO.factory('socketio', [
'$rootScope',
'addr',
function($rootScope, addr) {
var socket = io.connect(addr,{
'sync disconnect on unload': true
});
...
return socket;
}
]);
我试图注入它的地方:
angular.module('myApp.services', ['socketioModule'])
.provider('greeter', ['socketio', function(socket) {
var salutation = 'Hello';
this.setSalutation = function(s) {
salutation = s;
}
function Greeter(a) {
this.salutation = salutation;
socket._emit('hello')
this.greet = function() {
return salutation + ' ' + a;
}
}
this.$get = function(version) {
return new Greeter(version);
};
}]);
这导致
Error: [$injector:modulerr] Failed to instantiate module myApp due to:
[$injector:modulerr] Failed to instantiate module myApp.services due to:
[$injector:unpr] Unknown provider: socketio