2016-05-10 31 views
-1

我想使用的角度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

+0

假设适度最新版本,它是'$ uibModal'和'$ uibModalInstance'〜https://angular-ui.github.io/bootstrap/#/modal – Phil

回答

2

答案是从错误中,您使用的是您还没有定义/注入了一些供应商。

考虑到您在这里进行了多次注射,很难确切地说出问题所在,但从您给我们的错误中,没有供应商$modal。 AngularUI最近切换到uib作为它的大部分提供商和指令的前缀(即$uibModal)。尝试使用新版本。

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

+0

[2015年10月9日]( https://github.com/angular-ui/bootstrap/releases/tag/0.14.0)< - 不是最近。 – Phil

+0

实际上,直到V1.0.0才会删除对非前缀组件的支持。有一段时间的重叠让人们有机会迁徙。 –

相关问题