AngularJs ui.bootstrap - 模态显示错误[$ injector:unpr]

时间:2016-05-10 00:08:27

标签: angularjs angularjs-directive angular-ui-bootstrap

我正在尝试使用角度ui.bootstrap来实现某些功能,例如this,但这显示错误

  

[$注射器:unpr]   http://errors.angularjs.org/1.5.2/ $注射器/ unpr?P0 =%24modalProvider%20%3 C-%20%24modal%20%3 C-%20ngReallyClickDirective

我的代码是

app.js

var app = angular.module('app',['ui.router','oc.lazyLoad','ui.bootstrap','ngReallyClickModule']);

ngReallyClickModule.js

angular.module('ngReallyClickModule',['ui.router'])
    .directive('ngReallyClick', ['$modal',
        function($modal) {

            var ModalInstanceCtrl = function($scope, $modalInstance) {
                $scope.ok = function() {
                    $modalInstance.close();
                };

                $scope.cancel = function() {
                    $modalInstance.dismiss('cancel');
                };
            };

            return {
                restrict: 'A',
                scope:{
                    ngReallyClick:"&",
                    item:"="
                },
                link: function(scope, element, attrs) {
                    element.bind('click', function() {
                        var message = attrs.ngReallyMessage || "Are you sure ?";


                        var modalHtml = '<div class="modal-body">' + message + '</div>';
                        modalHtml += '<div class="modal-footer"><button class="btn btn-primary" ng-click="ok()">OK</button><button class="btn btn-warning" ng-click="cancel()">Cancel</button></div>';

                        var modalInstance = $modal.open({
                            template: modalHtml,
                            controller: ModalInstanceCtrl
                        });

                        modalInstance.result.then(function() {
                            scope.ngReallyClick({item:scope.item}); 
                        }, function() {
                            //Modal dismissed
                        });


                    });

                }
            }
        }
    ]);

查看

<a ng-really-message="Are you sure ?" ng-really-click="test(item)" item="item" ng-repeat="item in [1,2,3,4,5]">Delete</a>

我想在ng-really-click点击上进行模态对话。并在点击模态确定按钮时调用当前控制器的功能。

我正在使用angular-ui-routeroclazyLoading

1 个答案:

答案 0 :(得分:2)

答案来自错误,您使用的是某些尚未定义/注入的提供程序。

考虑到你在这里注射了很多次,很难确切地说是什么问题,但是从你给我们的错误来看,$modal没有提供者。 AngularUI最近切换到uib前缀大多数提供者和指令(即$uibModal)。尝试使用新版本。

https://angular-ui.github.io/bootstrap