Unknown Provider in AngularJS when Injecting custom service into different module

I am fairly new to AngularJS and have been working on trying to create a service that will wrap socket.io for a networking sandbox application.

I have created a 'NetworkServices' module in a separate file:

(function(){
    var app = angular.module('NetworkServices', []);
    app.factory('$socket', ['', function(){
        var Socket = {
            ip: '127.0.0.1',
            port: '8080',
            socket: null,
            Connect: function(ip, port, sock){
                Socket.ip = ip;
                Socket.port = port;
                Socket.log('Connecting to ' + Socket.ip + ':' + Socket.port);
                Socket.socket = window.io.connect(Socket.ip + ':' + Socket.port);
                sock = Socket.socket;
            }
        };
        return Socket;
    }]);
})();

And here is the module I am trying to inject the service into:

(function(){
    var app = angular.module('server', ['ui.bootstrap', 'NetworkServices']);

    app.controller('ServerCtrl',['$scope','$socket',  function ($scope, $socket) {
            var val = $scope;
            val.test = true;

            var self = this;
            self.isCollapsed = false;
            self.ip = '129.119.228.206';
            self.port = '8080';
            self.socket = {};

            self.Connect = function(){
                $socket.Connect(self.ip, self.port, self.socket);
            };
      }]);


    app.directive('server', function(){
        return {
            restrict: 'E',
            templateUrl: 'views/server.html',
            controller: 'ServerCtrl',
            controllerAs: 'server'
        };
    });


})();

When I add the $socket service to the server module, I get the following error:

Error: [$injector:unpr] Unknown provider: Provider <-  <- $socket

I have added the "NetworkServices' Module as a dependency to the "Server" module, but I cant tell why I do not have access to the $socket service? Any suggestions?

The problem is not with injecting the $socket service, but with creating it. In its definition, you define a dependency called '', that angular cannot create.

app.factory('$socket', ['', function(){...

Should be:

app.factory('$socket', function(){...

Since your method has no parameters, it has no dependencies to declare.

As a newbie to angular please note that using the '$' prefix before your own services is considered bad practice as it is reserved for angular's internal components and variables. The other answer about removing the empty string from your factory definition is accurate. The reason you include the square brackets around your factory definition would be to make it minification safe. Here are the 3 primary ways of defining factories:

The non minification safe version

app.factory('Socket', function ($log, $window) {
  function Socket(ip, port, socket) {
    this.ip = '127.0.0.1';
    this.port = '8080';
    this.socket: null;
  }

  Socket.prototype.connect = function (ip, port, sock){
    $log('Connecting to ' + Socket.ip + ':' + Socket.port);
    this.socket = $window.io.connect(Socket.ip + ':' + Socket.port);
    return this.socket;
  }

  return Socket;
});

Here is the square bracket min-safe version:

app.factory('Socket', ['$log', '$window', function ($log, $window) {
  function Socket(ip, port, socket) {
    this.ip = '127.0.0.1';
    this.port = '8080';
    this.socket: null;
  }

  Socket.prototype.connect = function (ip, port, sock){
    $log('Connecting to ' + Socket.ip + ':' + Socket.port);
    this.socket = $window.io.connect(Socket.ip + ':' + Socket.port);
    return this.socket;
  }

  return Socket;
}]);

Here is my preferred min-safe version (the way angular does it in their source code:

socketFactory.$inject = ['$log', '$window'];
function socketFactory($log, $window) {
  function Socket(ip, port, socket) {
    this.ip = '127.0.0.1';
    this.port = '8080';
    this.socket: null;
  }

  Socket.prototype.connect = function (ip, port, sock){
    $log('Connecting to ' + Socket.ip + ':' + Socket.port);
    this.socket = $window.io.connect(Socket.ip + ':' + Socket.port);
    return this.socket;
  }

  return Socket;
}

app.factory('Socket', socketFactory);

Now the controller would be much simpler.

app.controller('ServerCtrl',['Socket', function (Socket) {
  this.socketConfig = new Socket('129.119.228.206', '8080'),
  this.socket = socketConfig.connect();
}]);