我的Angularjs在哪里缩小错误?错误$ injector

Leo*_*ban 2 javascript minify angularjs angularjs-injector

我遇到了恼人的Angular minify问题(我真的希望Angular 2中不存在这个问题)

我已经注释掉了我的所有应用程序模块注入并逐一下载列表以找出问题所在,我想我将其缩小到我的searchPopoverDirectives:

你能看出我做错了什么吗?

原始代码,产生此错误 Unknown provider: eProvider <- e:

(function() { "use strict";

    var app = angular.module('searchPopoverDirectives', [])

    .directive('searchPopover', function() {
        return {
            templateUrl : "popovers/searchPopover/searchPopover.html",
            restrict    : "E",
            scope       : false,
            controller  : function($scope) {

                // Init SearchPopover scope:
                // -------------------------
                var vs = $scope;
                vs.searchPopoverDisplay = false;

            }
        }
    })

})();
Run Code Online (Sandbox Code Playgroud)

然后,我试图[]修复minify问题尝试语法并遇到此错误 Unknown provider: $scopeProvider <- $scope <- searchPopoverDirective:

(function() { "use strict";

    var app = angular.module('searchPopoverDirectives', [])

    .directive('searchPopover', ['$scope', function($scope) {
        return {
            templateUrl : "popovers/searchPopover/searchPopover.html",
            restrict    : "E",
            scope       : false,
            controller  : function($scope) {

                // Init SearchPopover scope:
                // -------------------------
                var vs = $scope;
                vs.searchPopoverDisplay = false;

            }
        }
    }])

})();
Run Code Online (Sandbox Code Playgroud)

更新: 还发现这家伙造成了问题:

.directive('focusMe', function($timeout, $parse) {
    return {
        link: function(scope, element, attrs) {
            var model = $parse(attrs.focusMe);
            scope.$watch(model, function(value) {
                if (value === true) { 
                    $timeout(function() {
                        element[0].focus(); 
                    });
                }
            });
            element.bind('blur', function() {
                scope.$apply(model.assign(scope, false));
            })
        }
    }
})
Run Code Online (Sandbox Code Playgroud)

Gru*_*ndy 8

当你缩小代码时,它会缩小所有代码,所以你的代码

controller  : function($scope) {
Run Code Online (Sandbox Code Playgroud)

被缩小到类似的东西

controller  : function(e) {
Run Code Online (Sandbox Code Playgroud)

所以,只需使用

controller  : ["$scope", function($scope) { ... }]
Run Code Online (Sandbox Code Playgroud)