AngularJS:未知的提供程序错误

时间:2015-03-03 08:05:10

标签: javascript angularjs

我收到了这个传奇的错误,我无法弄清楚原因:

 Uncaught Error: [$injector:modulerr] Failed to instantiate module myApp due to:
Error: [$injector:unpr] Unknown provider: AbastecsService

app.js

var myApp = angular.module("myApp", ["ngRoute", "ngResource", 
    "myApp.services", "myApp.controllers"]);

var controllers = angular.module("myApp.controllers", []);
var services = angular.module("myApp.services", []);

myApp.config(["$routeProvider", "$httpProvider", "AbastecsService",
    function($routeProvider, $httpProvider, AbastecsService) {

    $routeProvider

    .when("/", {
        templateUrl : "login.html",
        controller : "LoginController"
    })

    .when("/abastecimientos", {
        templateUrl : "main.html",
        controller : "AbastecsController",
        resolve : {
            abastecs : function(AbastecsService) {
                return AbastecsService.getAbastecimientos();
            }
        }
    });

}]);

abastecimientos_service.js

var services = angular.module("myApp.services");

services.service("AbastecsService", ["$resource", function($resource) {

    var ROOT_URL = "http://xxx.xxx.xxx.xxx"; 

    var Abastecimientos = 
        $resource(ROOT_URL + "/abastecimientos/2010101010101010");

    this.getAbastecimientos = function() {
        var abastecs = Abastecimientos.get(function() {
            return abastecs.data;
        });
    };

}]);

abastecimientos_controller.js

var controllers = angular.module("myApp.controllers");

controllers.controller("AbastecsController", ["$scope", "abastecs", 
    function($scope, abastecs){

    $scope.abastecs = abastecs;

}]);

login_controller.js

var controllers = angular.module("myApp.controllers");

controllers.controller("LoginController" , ["$scope", "$location", 
    function($scope, $location) {

    $scope.login = function() {
        $location.path("/abastecimientos");
    };

}]);

的index.html

<!DOCTYPE html>
<html>
<head>

    <link rel="shortcut icon" href="favicon32.ico" />
    <link href="css/bootstrap.min.css" rel="stylesheet" type="text/css">
    <link rel="stylesheet" type="text/css" href="/css/signin.css" media="screen" />

</head>

<body ng-app="myApp" id="page-top" data-spy="scroll" data-target=".navbar-custom">

    <div ng-view></div>

    <!-- JQuery -->
    <script src="lib/jquery/jquery-1.11.2.min.js"></script>

    <!--  angular-js -->
    <script src="lib/angularjs/angular.js"></script>
    <script src="lib/angularjs/angular-route.min.js"></script>
    <script src="lib/angularjs/angular-resource.min.js"></script>

    <script src="js/app.js"></script>
    <script src="js/controllers/login_controller.js"></script>
    <script src="js/controllers/abastecimientos_controller.js"></script>
    <script src="js/services/abastecimientos_service.js"></script>

    <!-- Bootstrap -->
    <script src="lib/bootstrap/js/bootstrap.min.js"></script>

</body>
</html>

感谢。

1 个答案:

答案 0 :(得分:0)

<强>解决!

问题是我在app.config注入我的服务而且它一定不是。然后就是这样:

myApp.config(["$routeProvider", "$httpProvider",
    function($routeProvider, $httpProvider, AbastecsService) {

...

}