"未捕捉错误:[$ injector:unpr]"尝试将数据从模态传递到控制器时

时间:2016-07-04 10:38:24

标签: javascript angularjs dependency-injection bootstrap-modal

我试图将一个对象(一个数组)从一个模态传递给一个控制器,但是我收到了这个错误:

"Uncaught Error: [$injector:unpr]" 

我已经声明了一个函数into resolve,它返回数组并将函数注入控制器,但它不起作用。我究竟做错了什么?

以下是模式:

$scope.cercaClienteNomeCognome = function() {
    if ($scope.nome == undefined){
        var name = "";
    } else name = angular.uppercase($scope.nome);
    if ($scope.cognome == undefined){
        var surname = "";
    } else surname = angular.uppercase($scope.cognome);
    var url = "servizi/getClienteNomeCognome?nomeCliente="+name+"&cognomeCliente="+surname;
    $http.get(url)
    .success(function(data, status, headers, config) {
        if (data.length > 0) {
            var modalInstance = $modal.open({
                templateUrl: 'partials/modals/estensioneRicerca.html',
                controller: 'estensioneRicercaController',
                size : 'lg',
                backdrop: 'static',
                //keyboard: false,
                resolve: {
                    returnArrayClienti: function () {
                           return data;
                         }
                }
            });
        }

    })
    .error(function(data, status, headers, config) {
        toaster.pop({
            type    : "Error",
            title   : "Ouh nou!",
            body    : "[RECUPERO CLIENTI] Errore durante il ritrovamento dei clienti"
        });
    });
}; 

这是控制器:

    angular.module("itasAcquire.controllers")
.controller('estensioneRicercaController', ['$scope', '$rootScope', 'ConfigPropertiesService', 'toaster', '$log', '$http', 'returnArrayClienti',
                      function ($scope, $rootScope, ConfigPropertiesService, toaster, $log, $http, returnArrayClienti) {


     $scope.mostraToasterTemporaneo = function() {
         var clienti = returnArrayClienti;
         var clienti = null;
            if (clienti == undefined) { 
                toaster.pop({
                    type    : "Success",
                    title   : "WAIT!",
                    body    : "Attenzione! Non e' stato selezionato alcun tipo documento!"

            });
            } else {
                toaster.pop({
                    type    : "Success",
                    title   : "Congrats!",
                    body    : "Il cliente è stato selezionato!  (" + clienti.CODICE_FISCALE + ")"
                });
            }
     };


}]);

编辑:按照错误的屏幕截图:
enter image description here

1 个答案:

答案 0 :(得分:0)

好的,我自己找到了一个解决方案:我很确定问题是关于控制器之间的冲突(因为模态是在ctrl1中,我将数据从模态传递到ctrl2)所以我所要做的就是添加一个包含所有模态逻辑的服务......