【问题标题】:JSHint (r10): 'angular' is not definedJSHint (r10): 'angular' 未定义
【发布时间】:2014-01-17 04:43:37
【问题描述】:

我有以下几点:

angular.module('test')
    .controller('TestMenuController',
    [
        '$http',
        '$scope',
        '$resource',
        '$state',
        'os',
        'us',
    function (
        $http,
        $scope,
        $resource,
        $state,
        os,
        us) {

当我在 VS2014 中构建它时,它给了我一条错误消息:

JSHint (r10): 'angular' is not defined. 

有人可以告诉我如何避免出现此消息吗?

【问题讨论】:

标签: visual-studio angularjs jshint


【解决方案1】:

解决此问题的一种方法是修改您的 .jshintrc 并将 angular 设置为预定义变量之一,正如 Jayantha 所说。

.jshintrc 看起来像这样:

{
  "predef": ["angular"]
}

【讨论】:

【解决方案2】:
  • 一种方法是在配置选项中添加“角度”作为全局变量,
  • 或通过将配置选项“jshintrc”路径设置为.jshintrc
  • documentation(配置jshint选项的不同方式)

如果你正在使用 grunt..

  //------------------------//
  // jshint
  //------------------------//
  /**
   * JSHint: configurations
   * https://github.com/gruntjs/grunt-contrib-jshint
   */
  jshint: {
    options: {
      jshintrc: '.jshintrc',
      jshintignore: '.jshintignore',
      reporter: require('jshint-stylish')
    },
    gruntfile: {
      src: 'Gruntfile.js'
    },
    scripts: {
      src: '<%= project.scripts %>/**/*.js'
    },
    all: [
      'Gruntfile.js',
      '<%= project.js %>/*.js',
      '<%= project.scripts %>/**/*.js',
      'test/**/*.js'
    ]
  },

在 .jshintrc(在根目录)中包含我的以下选项

{
  "curly"   : true,
  "eqeqeq"  : true,
  "undef"   : true,
  "jquery"  : true,

  // global variables
  "globals": {
    "angular"   : false,
    "jasmine"   : false,
    "$"         : false,
    "_"         : false,
    "module"    : false,
    "require"   : false
  }
}

希望这会有所帮助。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2015-07-10
    • 2013-09-07
    • 2012-02-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-07-29
    相关资源
    最近更新 更多