0

I have the following code and it works fine:

app.main.js:

angular.module('app', ['ngAnimate', 'ui.router'])
.factory('_', function() {
  return window._;
});

angular.module('app').run(['$route', '$rootScope', '$location', function ($route, $rootScope, $location) {
    var original = $location.path;
    $location.path = function (path, reload) {
        if (reload === false) {
            var lastRoute = $route.current;
            var un = $rootScope.$on('$locationChangeSuccess', function () {
                $route.current = lastRoute;
                un();
            });
        }
        return original.apply($location, [path]);
    };
}]);

bservice:

angular.module('app')
  .service('bService', ['$http', '_', function($http, _) { ...

But when I try to separate de factory to a different file I get the Angular Error: $injector:unpr Unknown Provider. This file looks like this:

angular.module('app').factory('_', function() {
  return window._;
});

I also made sure that the factory file is included.

Thanks

EDIT

Full error: Unknown provider: _Provider

KBeckers
  • 416
  • 4
  • 12
  • Can you post the full error? Which provider is unknown? – SteamDev Jul 07 '16 at 21:28
  • Possible duplicate of [AngularJS Error: $injector:unpr Unknown Provider](http://stackoverflow.com/questions/23942356/angularjs-error-injectorunpr-unknown-provider) – str Jul 07 '16 at 21:28
  • Did you include the new file in your HTML? – str Jul 07 '16 at 21:34
  • Yes I use gulp to merge all js files. – KBeckers Jul 07 '16 at 21:34
  • Are you including the `_` factory before `bService`? The order may be important since `bService` depends on `_`. – SteamDev Jul 07 '16 at 21:37
  • I guess gulp didn't like the name `factorys` in the folder structure ( Wrong spelled ). If i change it to something like `fact` everything works fine. Thanks guys – KBeckers Jul 07 '16 at 21:47

1 Answers1

0

I use gulp for the file merges. So everything is in one file.

Gulp didn't like the name factorys. Because of this my factory became damaged in the main .js file.

The solution was to rename the folder to anything els then factorys.

KBeckers
  • 416
  • 4
  • 12