我的Angularjs在哪里缩小错误?错误$ injector [英] Where is my Angularjs minify error? Error $injector

查看:78
本文介绍了我的Angularjs在哪里缩小错误?错误$ injector的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我遇到了烦人的Angular缩小问题(我真的希望Angular 2中不存在此问题)

I'm running into that annoying Angular minify problem (I really hope this issue is non-existent in Angular 2)

我已经注释掉我所有的应用模块注入,并逐一列出列表,以找出问题所在,我认为我将其范围缩小到了 searchPopoverDirectives :

I've commented out all my app module injections and going down the list 1 by 1 to find out where the problem is and I think I narrowed it down to my searchPopoverDirectives:

你能看到我在做什么吗?

Can you see what I'm doing wrong?

原始代码产生 此错误 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;

            }
        }
    })

})();

然后我尝试使用[]语法尝试解决缩小问题,并遇到了

I then tried the [] syntax in an attempt to fix the minify problem and ran into this error 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;

            }
        }
    }])

})();


更新: 还发现这家伙引起了问题:


UPDATE: Also found out this guy is causing a problem:

.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));
            })
        }
    }
})

推荐答案

当您压缩代码时,它会压缩所有代码,因此您的

When you minify code, it minify all code, so your

controller  : function($scope) {

缩小为

controller  : function(e) {

所以,只需使用

controller  : ["$scope", function($scope) { ... }]

这篇关于我的Angularjs在哪里缩小错误?错误$ injector的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆