Angular bootstrap modal causing strict-di error, not sure why

前端 未结 2 2043
日久生厌
日久生厌 2021-01-19 07:18

Weird problem, using Angular UI bootstrap modal I have no issues at all with Angular 1.3 beta 16, however if I enable ng-strict-di mode I get the following error:

         


        
相关标签:
2条回答
  • 2021-01-19 07:52

    From the documentation it looks like you need to declare all dependency injections in string array.

    There are other ways but normally I would do it like this:

    controller: ['$scope', '$modalInstance', ModalInstanceCtrl]
    
    0 讨论(0)
  • 2021-01-19 08:07

    You need to manually advertise your dependencies for the controller since you have ng-strict-di enabled.

    function ModalInstanceCtrl ($scope, $modalInstance) { //or var ModalInstanceCtrl = function(...
    
      $scope.ok = function () {
        $modalInstance.close(true);
      };
    
      $scope.cancel = function () {
        $modalInstance.dismiss(false);
      };
    
    };
    
    ModalInstanceCtrl.$inject = ['$scope', '$modalInstance'];
    
    0 讨论(0)
提交回复
热议问题