Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/392.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 当我最小化代码时,代码停止工作_Javascript_Gulp_Minify_Gulp Uglify - Fatal编程技术网

Javascript 当我最小化代码时,代码停止工作

Javascript 当我最小化代码时,代码停止工作,javascript,gulp,minify,gulp-uglify,Javascript,Gulp,Minify,Gulp Uglify,有一个工作代码: 代码在吞咽时不起作用uglify() 以下代码中的错误在哪里 var app = angular.module('app', ['ui.sortable', 'Myanimate']); angular.module('Myanimate', []) .factory('animate', function() { var time = 3000; var timeout = null; return { _hideAnim

有一个工作代码:

代码在吞咽时不起作用uglify()

以下代码中的错误在哪里

var app = angular.module('app', ['ui.sortable', 'Myanimate']);

angular.module('Myanimate', [])
    .factory('animate', function() {

    var time = 3000;
    var timeout = null;

    return {
        _hideAnimate: function(item) {      
            timeout = timeout || setTimeout(function() {
                this.removeBackground(item);

                timeout = null;
            }.bind(this), time);    
        },

        setBorder : function(item) {
            item.addClass('red-border');
            this.removeBorder(item);
            this._hideAnimate(item);
            return item;
        },
        setBackground: function(item) {
            item.addClass('red-border red-border-background');
            this._hideAnimate(item);
            return item;
        },
        removeBorder : function(item) {
            item.removeClass('red-border-background');
            return item;
        },
        removeBackground: function(item) {
            item.removeClass('red-border red-border-background');   
            return item;
        }
    }
});

app.controller('appController', function ($scope, animate) {

  $scope.list1 = ['A', 'B', 'C'];
  $scope.list2 = ['1', '2', '3'];
  $scope.list3 = ['X', 'Y', 'Z'];
  $scope.elemMoved = null;

  $scope.sortableOptions = {
    over : function(e,ui) {
    var $targetElem = $(e.target);

      if($targetElem.hasClass('second')) {
        animate.setBorder(ui.item);
      } else if($targetElem.hasClass('third')) {    
        animate.setBackground(ui.item);
      } else {
        animate.removeBackground(ui.item);  
      }
    },

    update: function(e, ui) {

    var moveItem =  $scope.elemMoved = ui.item.sortable.moved;
    var ngModel = $(ui.item.sortable.droptarget).attr('ng-model');

    if(typeof moveItem === 'undefined') {
        return;
    }

     if($(ui.item.sortable.droptarget).hasClass('third')) {   
      if($.inArray(moveItem, $scope.list1) === -1) {
          if(ui.item.sortable.droptarget || e.target != ui.item.sortable.droptarget[0]) {
                $scope.list1.push(moveItem);
          }
      } 
    }

    },
    stop: function(e, ui) {
        ui.item.removeClass('red-border red-border-background');      
    },
    connectWith: ".apps-container"
  };

});

您需要更改代码并包含一个数组,其中包含要注入控制器的内容

app.controller('appController', function ($scope, animate)
应该是

app.controller('appController', ['$scope', 'animate', function ($scope, animate) {
    // ...
}]);
您还可以使用这样的工具,它会自动执行此操作,因此您可以添加

.pipe(ngAnnotate({
    // true helps add where @ngInject is not used. It infers.
    // Doesn't work with resolve, so we must be explicit there
    add: true
}))
只需使用函数上方的注释即可

/* @ngInject */
app.controller('appController', function ($scope, animate)

现在,angular将知道即使在变量被缩小后注入什么

浏览器控制台说什么?什么都没有。一切都能解决-最小化文件。但在那之后,一切都不起作用
/* @ngInject */
app.controller('appController', function ($scope, animate)