【问题标题】:Ui-router modal injection error on minification缩小时的ui-router模态注入错误
【发布时间】:2014-10-17 11:56:31
【问题描述】:

我正在使用 ui-router 和 ui-bootstrap/modal

我有一个分成两部分的销售屏幕,所以我的左侧是购物车,右侧是目录、编辑产品或付款部分。

我需要在所有状态下都有一个模式,所以我创建了一个函数来添加一些 ui-router 状态。 函数如下:

var modalSaleDelete = ['$state', '$modal',
    function($state, $modal) {
      $modal.open({
        templateUrl: 'views/sale/delete.html',
        resolve: {
          parentScope: function($rootScope) {
            return $rootScope.parentScope;
          }
        },
        controller: function($scope, parentScope) {

          $scope.delete = function() {
            // TODO: change the way this is called
            parentScope.resetOrder();

            parentScope = null;
            $scope.$close('cancel');
          };

          $scope.cancel = function() {
            parentScope = null;
            $scope.$dismiss('cancel');
          };
        }
      }).result.then(function() {
        return $state.transitionTo($state.$current.parent);
      }, function() {
        return $state.transitionTo($state.$current.parent);
      });
    }
  ];

然后我把它放在每个状态:

    .state('sale.new.catalog.delete', {
      url: '/delete',
      onEnter: modalSaleDelete
    })

它在开发中效果很好,但是当我缩小它时,我得到一个错误:

Error: [$injector:unpr] Unknown provider: aProvider <- a
http://errors.angularjs.org/1.2.24/$injector/unpr?p0=aProvider%20%3C-%20a
    at http://localhost/ociWeb/code/dist/scripts/vendor.29d508bc.js:3:26944
    at http://localhost/ociWeb/code/dist/scripts/vendor.29d508bc.js:4:11462
    at Object.c [as get] (http://localhost/ociWeb/code/dist/scripts/vendor.29d508bc.js:4:10723)
    at http://localhost/ociWeb/code/dist/scripts/vendor.29d508bc.js:4:11557
    at c (http://localhost/ociWeb/code/dist/scripts/vendor.29d508bc.js:4:10723)
    at Object.d [as invoke] (http://localhost/ociWeb/code/dist/scripts/vendor.29d508bc.js:4:11008)
    at http://localhost/ociWeb/code/dist/scripts/vendor.29d508bc.js:8:20044
    at Object.f [as forEach] (http://localhost/ociWeb/code/dist/scripts/vendor.29d508bc.js:3:27387)
    at j (http://localhost/ociWeb/code/dist/scripts/vendor.29d508bc.js:8:19961)
    at Object.k.open (http://localhost/ociWeb/code/dist/scripts/vendor.29d508bc.js:8:20414) 

我已经调试过了,aProvider 应该是 '$state'。

你知道如何让它发挥作用吗?

【问题讨论】:

    标签: angularjs angular-ui-bootstrap angular-ui-router bootstrap-modal


    【解决方案1】:

    您需要对每次注入进行注释才能使缩小工作。或者,如果您使用的是 angular-aware minifier,它可能不了解 UI-Router 注入了哪些函数,哪些是标准函数。

    var modalSaleDelete = ['$state', '$modal',
        function($state, $modal) {
          $modal.open({
            templateUrl: 'views/sale/delete.html',
            resolve: {
              parentScope: [ '$rootScope', function($rootScope) {
                return $rootScope.parentScope;
              }]
            },
            controller: [ '$scope', 'parentScope', function($scope, parentScope) {
    
              $scope.delete = function() {
                // TODO: change the way this is called
                parentScope.resetOrder();
    
                parentScope = null;
                $scope.$close('cancel');
              };
    
              $scope.cancel = function() {
                parentScope = null;
                $scope.$dismiss('cancel');
              };
            }]
          }).result.then(function() {
            return $state.transitionTo($state.$current.parent);
          }, function() {
            return $state.transitionTo($state.$current.parent);
          });
        }
      ];
    

    【讨论】:

    • 我实际上正在使用一个角度感知缩小器,正如你所说,我需要在正确的位置注入 $state。问题是找到它,因为堆栈只显示供应商函数,所以我真的不知道从哪里开始调试我的部分。不过感谢您的帮助
    【解决方案2】:

    尝试通过创建注入属性手动注入它们。你有 jsfiddle 或 plunker 设置吗?

      modalSaleDelete.$inject = ['$state', '$modal'];
    

    【讨论】:

      【解决方案3】:

      嗯,我想通了。我不明白为什么,但问题已经解决。 我解决了它注入 '$state' 的问题,尽管它不是必需的。 调试时,我刚刚看到 aProvider 正试图注入其中。

      var modalSaleDelete = ['$rootScope', '$state', '$modal',
          function($rootScope, $state, $modal) {
            $modal.open({
              templateUrl: 'views/sale/delete.html',
              resolve: {
                parentScope: ['$state', '$rootScope', function($state, $rootScope) {
                  return $rootScope.parentScope;
                }]
              },
              controller: ['$scope', '$state', 'parentScope', function($scope, $state, parentScope) {
      
                $scope.delete = function() {
                  // TODO: change the way this is called
                  parentScope.resetOrder();
      
                  parentScope = null;
                  $scope.$close();
                };
      
                $scope.cancel = function() {
                  parentScope = null;
                  $scope.$dismiss();
                };
              }]
            }).result.then(function() {
              // close
              return $state.transitionTo($state.current.name.replace('.delete', ''));
            }, function() {
              // dismiss
              return $state.transitionTo($state.current.name.replace('.delete', ''));
            });
          }
        ];
      

      【讨论】:

        猜你喜欢
        • 2016-01-14
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多