Uncaught ReferenceError: $stateProvider is not defined Angular UI Router

Issue

For some reason I’m getting this error Uncaught ReferenceError: $stateProvider is not defined even though angular-ui-router.js is being loaded fine.

the error in Dev Tools

enter image description here

here is my app.js

var app = angular.module('app', ['ui.router']);

app.config([$stateProvider, $urlRouterProvider, function($stateProvider, $urlRouterProvider) {

      $urlRouterProvider.otherwise('/');

      $stateProvider
        .state('main',
          { 
            url: '/',
            templateUrl: '/partials/main', 
            controller: 'mainCtrl'
          });
    }
]);

Solution

app.config([$stateProvider, $urlRouterProvider, function($stateProvider, $urlRouterProvider) 

should read

app.config(['$stateProvider', '$urlRouterProvider', function($stateProvider, $urlRouterProvider)`

As @charlietfl pointed out its missing quotes.

Answered By – user1135469

Answer Checked By – Pedro (AngularFixing Volunteer)

Leave a Reply

Your email address will not be published.