user3818383
user3818383

Reputation: 170

Error on removing # from URL using $locationProvider

I keep getting Uncaught Error: [$injector:modulerr] when using $locationProvider to remove the # from root. How can I fix it?

var myApp = angular.module('myApp', ['ngRoute']);

// routes
myApp.config(function($routeProvider, $locationProvider) {
  $routeProvider
  .when('/', {
      templateUrl : 'views/home.html',
      controller  : 'mainController'
   });

  $locationProvider.html5Mode(true);
});

myApp.controller('mainController', function($scope) {
  $scope.message = 'hello';
});

I am calling both angular/angular-route and using base href="/" on head.

Upvotes: 0

Views: 48

Answers (1)

Vitor Leal
Vitor Leal

Reputation: 65

Are you minifying the code?

You should add the dependencies as string before the function arguments.

myApp.config(['$routeProvider', '$locationProvider', function($routeProvider, $locationProvider) {
    $routeProvider
        .when('/', {
            templateUrl: 'views/home.html',
            controller : 'mainController'
    });

    $locationProvider.html5Mode(true);
}]);

Upvotes: 1

Related Questions