“Unknown provider: aProvider <- a” How do I find the original provider?

后端 未结 9 653
自闭症患者
自闭症患者 2020-12-07 08:46

When I\'m loading the minified (through UglifyJS) version of my AngularJS application, I get the following error in the console:

Unknown provider: aProvider          


        
相关标签:
9条回答
  • 2020-12-07 09:44

    Also do not forget the resolve property of the route. It also must be defined as the array:

    $routeProvider.when('/foo', {
        resolve: {
            bar: ['myService1', function(myService1) {
                return myService1.getThis();
            }],
            baz: ['myService2', function(myService2) {
                return myService2.getThat();
            }]
        }
    });
    
    0 讨论(0)
  • 2020-12-07 09:45

    With generator-gulp-angular:

       /** @ngInject */
        function SomeController($scope, myCoolService) {
    
    }
    

    Write /** @ngInject */ before each controller, service, directive.

    0 讨论(0)
  • 2020-12-07 09:47

    Oliver Salzburg's write-up was fantastic. Upvoted.

    Tip for anyone who might have this error. Mine was simply caused by forgetting to pass in an array for a directive controller:

    BAD

    return {
        restrict: "E",
        scope: {                
        },
        controller: ExampleDirectiveController,
        templateUrl: "template/url/here.html"
    };
    

    GOOD

    return {
        restrict: "E",
        scope: {                
        },
        controller: ["$scope", ExampleDirectiveController],
        templateUrl: "template/url/here.html"
    };
    
    0 讨论(0)
提交回复
热议问题