JSHint(r10):'angular'未定义

Sam*_*tar 39 visual-studio jshint angularjs

我有以下内容:

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

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

JSHint (r10): 'angular' is not defined. 
Run Code Online (Sandbox Code Playgroud)

有人能告诉我如何避免这个消息出现吗?

Nic*_*fal 90

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

.jshintrc 看起来像这样:

{
  "predef": ["angular"]
}
Run Code Online (Sandbox Code Playgroud)


小智 13

  • 一种方法是在配置选项中添加'angular'作为全局变量,
  • 或者通过将配置选项'jshintrc'路径设置为.jshintrc
  • 文档(配置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'
    ]
  },
Run Code Online (Sandbox Code Playgroud)

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

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

  // global variables
  "globals": {
    "angular"   : false,
    "jasmine"   : false,
    "$"         : false,
    "_"         : false,
    "module"    : false,
    "require"   : false
  }
}
Run Code Online (Sandbox Code Playgroud)

希望这可以帮助.


归档时间:

查看次数:

16106 次

最近记录:

10 年,5 月 前