Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/typo3/2.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_Angularjs_Coffeescript_Gruntjs_Grunt Contrib Uglify - Fatal编程技术网

“咕哝任务”;“丑陋的”;更改了JavaScript代码,现在源代码不再工作

“咕哝任务”;“丑陋的”;更改了JavaScript代码,现在源代码不再工作,javascript,angularjs,coffeescript,gruntjs,grunt-contrib-uglify,Javascript,Angularjs,Coffeescript,Gruntjs,Grunt Contrib Uglify,咕噜的任务“丑”改变了我的代码,所以它不再工作了。我是CoffeeScript、AngularJS、grunt等的初学者。为了解决这个问题,我必须对我的CoffeeScript代码进行哪些更改 我不知道为什么“丑八怪”会这样改变我的代码。JavaScript代码在我看来很好 咖啡脚本代码: # add background and some style just for specific page .directive('customBackground', () -> return

咕噜的任务“丑”改变了我的代码,所以它不再工作了。我是CoffeeScript、AngularJS、grunt等的初学者。为了解决这个问题,我必须对我的CoffeeScript代码进行哪些更改

我不知道为什么“丑八怪”会这样改变我的代码。JavaScript代码在我看来很好

咖啡脚本代码:

# add background and some style just for specific page
.directive('customBackground', () ->
  return {
  restrict: "A"
  controller: [
    '$scope', '$element', '$location'
    ($scope, $element, $location) ->
      path = ->
        return $location.path()

      addBg = (path) ->
        # remove all the classes
        $element.removeClass 'body-home body-special body-tasks body-lock'

        # add certain class based on path
        switch path
          when '/' then $element.addClass 'body-home'
          when '/404', '/500', '/signin' then $element.addClass 'body-special'

      addBg $location.path()

      $scope.$watch(path, (newVal, oldVal) ->
        if newVal is oldVal
          return
        addBg $location.path()
        return
      )
      return
  ]
  }
)
编译的JS代码

.directive('customBackground', function() {
    return {
      restrict: "A",
      controller: [
        '$scope', '$element', '$location', function($scope, $element, $location) {
          var addBg, path;
          path = function() {
            return $location.path();
          };
          addBg = function(path) {
            $element.removeClass('body-home body-special body-tasks body-lock');
            switch (path) {
              case '/':
                return $element.addClass('body-home');
              case '/404':
              case '/500':
              case '/signin':
                return $element.addClass('body-special');
            }
          };
          addBg($location.path());
          $scope.$watch(path, function(newVal, oldVal) {
            if (newVal === oldVal) {
              return;
            }
            addBg($location.path());
          });
        }
      ]
    };
  })
执行“丑陋”任务后的JS代码

.directive("customBackground", function () {
    return{restrict: "A", controller: ["$scope", "$element", "$location", function ($scope, $element, $location) {
        var addBg, path;
        path = function () {
            return $location.path()
        }, addBg = function (path) {
            switch ($element.removeClass("body-home body-special body-tasks body-lock"), path) {
                case"/":
                    return $element.addClass("body-home");
                case"/404":
                case"/500":
                case"/signin":
                    return $element.addClass("body-special")
            }
        }, addBg($location.path()), $scope.$watch(path, function (newVal, oldVal) {
            newVal !== oldVal && addBg($location.path())
        })
    }]}
})

你所说的
不再工作是什么意思?它会抛出任何异常吗?我没有得到任何异常。这个指令已经不起作用了。它不再改变CSS类。在path函数是分号的逗号实例之后,等等……您使用哪种浏览器?它可以工作,JSFIDLE:,您必须检查其他丑陋的文件现在,我怀疑我的其他文件在全局范围内包含“use strict”。