" $ injector:unpr未知提供商"在$ stateProvider中添加resolve后

时间:2015-11-25 12:45:19

标签: angularjs

我已经搜索过类似的问题,但无法弄清楚我的具体情况是什么问题。也许你们其中一个人有想法?

我的代码执行时没有出错,但我必须将resolve添加到$stateProvider。这样做之后我得到了以下错误:

Error: [$injector:unpr] Unknown provider: rquoteShipmentListProvider <- rquoteShipmentList <- vendorQuoteCtrl http://errors.angularjs.org/1.4.7/$injector/unpr?p0=rquoteShipmentListProvider%20%3C-%20rquoteShipmentList%20%3C-%20vendorQuoteCtrl at Anonymous function (https://code.angularjs.org/1.4.7/angular.js:4289:13) ...

我的代码:

var app = angular.module("offerModul", ["ui.router", "ui.bootstrap"]); 

app.config(function($stateProvider, $urlRouterProvider){

    $urlRouterProvider.otherwise("/");

    $stateProvider
    .state("main",{
        url: "/",
        controller:'vendorQuoteCtrl',
        templateUrl:'src/html/vendorQuoteRequest.html',
        resolve: {
            rquoteShipmentList: function(shipmentService) {
                return shipmentService.loadquoteShipments();
            }
        }
    });
});

app.controller('vendorQuoteCtrl', ['$scope', 'shipmentService', 'carrierService', 'chargesService', 'rquoteShipmentList', function($scope, shipmentService, carrierService, chargesService, rquoteShipmentList) {
    $scope.quoteShipmentList = rquoteShipmentList;

    $scope.open = function ()
    {
        init();
    }

    function init() {
        $scope.quoteShipmentList = shipmentService.getquoteShipments();
    }
}]);

app.service('shipmentService', ['$http', function ($http) {
    var quoteShipmentList = null;

    return {
        loadquoteShipments: function () {
            $http.get("./src/data/getShipments.php",{
                cache: true})
                .success(function (response) { quoteShipmentList = response; alert("quoteShipmentList:" + quoteShipmentList);})
                .error(function (data, status) {
                    alert("error getting Quotes! status:"+status);
            });
            alert("should be set:" + quoteShipmentList);
            return quoteShipmentList;
        },
        getquoteShipments: function () {
            return quoteShipmentList;

        }
    };

}]);

在添加resolve之前,我的代码执行时没有错误。之前的代码:

var app = angular.module("offerModul", ["ui.router", "ui.bootstrap"]); 

app.config(function($stateProvider, $urlRouterProvider){

    $urlRouterProvider.otherwise("/");

    $stateProvider
    .state("main",{
        url: "/",
        controller:'vendorQuoteCtrl',
        templateUrl:'src/html/vendorQuoteRequest.html'
    });
});

app.controller('vendorQuoteCtrl', ['$scope', 'shipmentService', 'carrierService', 'chargesService', function($scope, shipmentService, carrierService, chargesService) {
    $scope.quoteShipmentList = shipmentService.loadquoteShipments();

    $scope.open = function ()
    {
        init();
    }

    function init() {
        $scope.quoteShipmentList = shipmentService.getquoteShipments();
    }
}]);

app.service('shipmentService', ['$http', function ($http) {
    var quoteShipmentList = null;
    var shipmentList = null;

    return {
        loadquoteShipments: function () {
            $http.get("./src/data/getShipments.php",{
                cache: true})
                .success(function (response) { quoteShipmentList = response; alert("quoteShipmentList:" + quoteShipmentList);})
                .error(function (data, status) {
                    alert("error getting Quotes! status:"+status);
            });
            alert("should be set:" + quoteShipmentList);
            return quoteShipmentList;
        },
        getquoteShipments: function () {
            return quoteShipmentList;

        }
    };

}]);

非常感谢你的帮助!!!

2 个答案:

答案 0 :(得分:1)

像在其他帖子中推荐我从我的HTML中删除了ng-controller但是我没有看到在模态对话框中有另一个(?: - /)。 删除该标记删除了错误! 感谢您的帮助!

答案 1 :(得分:0)

解决方案存在问题。你必须像我们注入控制器一样注入你的服务shippingService。

类似的东西:

resolve: {     
    rquoteShipmentList: ['rquoteShipmentList', function (rquoteShipmentList){
        return shipmentService.loadquoteShipments();
    }],
}