Mercer
Mercer

Reputation: 9986

JSHint error: myApp is not defined (W117)

Why i have this error with jshint ..? :

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

My 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: '/'
            });
    });

Upvotes: 1

Views: 2891

Answers (3)

T.J. Crowder
T.J. Crowder

Reputation: 1075029

Because...myApp is not defined. Add a var in front of it to declare it. Otherwise, you're relying on The Horror of Implicit Globals (which only "works" in loose mode anyway), so JSHint is quite rightly telling you not to do that.

Upvotes: 2

Nils
Nils

Reputation: 806

First thing is you need to use var myApp there instead of myApp only.

Secondly you don't need to.

Even if you use var myApp, a global variable would be created. To avoid it, use angular.module('autoApp') (no second argument) wherever you want reference to myApp.

Upvotes: 1

NDY
NDY

Reputation: 3557

The error describes the problem perfectly. myApp is not defined. Define it with

var myApp

Upvotes: 2

Related Questions