为什么我在使用 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/