javascript - JSHint 错误 : myApp is not defined (W117)

标签 javascript angularjs

为什么我在使用 jshint 时出现此错误 ..? :

JSHint: 'myApp' is not defined. (W117)

我的 app.js:

myApp = angular.module('autoApp', ['ngRoute', 'uiGmapgoogle-maps', 'ngTable', 'ngAnimate', 'ngTouch'])
    .config(function ($routeProvider) {
        $routeProvider
            .when('/', {
                templateUrl: '/partials/cars.html',
                controller: 'AutoAppCtrl'
            }).when('/contact', {
                templateUrl: '/partials/contact.html',
                controller: 'ContactCtrl'
            }).when('/services', {
                templateUrl: '/partials/services.html',
                controller: 'AutoAppCtrl'
            }).when('/carDetails/:id', {
                templateUrl: '/partials/carDetails.html',
                controller: 'CarDetailsCtrl'
            }).otherwise({
                redirectTo: '/'
            });
    });

最佳答案

因为...myApp 没有定义。在它前面加一个var来声明它。否则,您将依赖 The Horror of Implicit Globals (无论如何它只能在松散模式下“工作”),所以 JSHint 非常正确地告诉你不要那样做。

关于javascript - JSHint 错误 : myApp is not defined (W117),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29096355/

相关文章:

javascript - Angular.js : Translate not working on Internet Explorer 11

javascript - 为什么在表单内填充 ng-model 后应该跟上 $scope.$apply?

javascript - For Each 循环中的 Promise 在 AngularJS 中不起作用

javascript - 在 $routeProvider 中组合 .when() 方法

php - javascript中的ie8 split函数问题

javascript - 在基于 polymer 的游戏中 : how to display an image depending on the total score

javascript - 输入=时间,如何只允许输入小时。没有分钟或秒

javascript - 如何恢复 Angular 1 Ng 模型的变化

javascript - Asp.net 页面在 Internet Explorer 7 和 7+ 版本中加载奇怪的内容

javascript - Google Place API - 请求的资源上不存在 'Access-Control-Allow-Origin' header 。因此不允许访问 Origin 'null'