Angular:$ uibModal undefined

时间:2016-05-24 10:38:00

标签: javascript html angularjs twitter-bootstrap angular-ui-bootstrap

当我使用ui.bootstrap.modal时出现此错误:

Error: $uibModal is undefined

模块:

    (function(angular) {
    /**
     * finanziarioTerziController
     *
     * a controller defined in the finanziarioTerziModule and using a sample service.
     */
    angular.module('finanziarioTerziModule')
        .controller('finanziarioTerziController', ['$scope', 'finanziarioTerziService', function ($scope, finanziarioTerziService) {
            'use strict';

            $scope.elencoPatrimonioTerziCollapsed = true;
            $scope.elencoPatrimonioTerzi = new Array();

            $scope.products = [];

            $scope.productToAdd = [];

            $scope.saveProduct = function (productToAdd) {
                for (var i = 0; i < productToAdd.length; i++) {
                    $scope.products.push(productToAdd[i]);
                    console.log($scope.products[i]);
                }
                $scope.reset();
            };


            $scope.reset = function () {
                $scope.productToAdd.length = 0;
            };

            $scope.remove = function (index) {
                $scope.productToAdd.splice(index, 1);
            };

            $scope.addProduct = function () {
                $scope.productToAdd.push({
                    tipologia: '',
                    descrizione: '',
                    contratto: '',
                    ctv: '',
                    possesso: ''
                });
            };

            $scope.open = function ($uibModal) {
                var modalInstance = $uibModal.open({
                    animation: $scope.animationsEnabled,
                    templateUrl:  'finanziarioTerziSearch.html' ,
                    controller: 'finanziarioTerziModule',
                    resolve: {
                        items: function () {
                            return $scope.items;
                        }
                    }
                });
            };
            open.$inject = '$uibModal';

            finanziarioTerziService.getPatrimonioTerzi().then(function (response) {

                if (response.status != '200') {
                    console.log('status diverso da 200');
                    return;
                }

                var elenco = response.data;

                for (var i = 0; i < elenco.length; i++) {
                    $scope.elencoPatrimonioTerzi.push(elenco[i]);
                }
            });
        }]);
})(angular);

模板(.html文件)

<div class="modal-header">
<h3 class="modal-title">This is template 1</h3>
</div>
<div class="modal-body">
<ul>
    <li ng-repeat="item in items">
        <a href="#" ng-click="$event.preventDefault(); selected.item = item">{{ item }}</a>
    </li>
</ul>
Selected: <b>{{ selected.item }}</b></div>

按钮(在另一个控制器内)

 <button class="btn btn-default" ng-click="open()" >Cerca Prodotto</button> 

我尝试在控制器中注入$ uibModel,但无法正常工作 对不起我的语言,我意大利语

编辑:在index.html

 <script src="../bower_components/jquery/dist/jquery.js"></script>
    <script src="../bower_components/angular/angular.js"></script>
    <script src="../bower_components/angular-bootstrap/ui-bootstrap-tpls.js"></script>
    <script src="../bower_components/angular-route/angular-route.js"></script>
    <script src="../bower_components/angular-ui-router/release/angular-ui-router.js"></script>

EDIT2:调整ng-controller 编辑3:在app.js

angular.module('patrimonioApp',['ngRoute', 'ui.bootstrap', 'ui.router',
    'commonModule', 'homeModule', 'finanziarioModule', 'polizzeModule', 'finanziarioTerziModule' ])
.config(['$routeProvider', function($routeProvider) {

编辑4:我解决了,但现在我有一个新的错误

1 个答案:

答案 0 :(得分:4)

正如我所知,您在控制器中注入依赖项的顺序与参数列表不匹配。请更正。

angular.module('finanziarioTerziModule')
    .controller('finanziarioTerziController', ['$scope', 'finanziarioTerziService','$uibModal', function ($scope, $uibModal, finanziarioTerziService) {

$ uibModal在注射列表中排名第三,但在params列表中排名第二。订单应该相同。 PFB正确的订单。

angular.module('finanziarioTerziModule')
    .controller('finanziarioTerziController', ['$scope', 'finanziarioTerziService','$uibModal', function ($scope, finanziarioTerziService, $uibModal) {

请更正订单,看看是否有效。我希望如此。