1

I'm trying remove from my url #, but when I add $locationProvider.html5Mode(true); and my app.js and <base href='/'> on my HTML, I get an error from AngularJS:

Uncaught Error: [$injector:modulerr] http://errors.angularjs.org/1.5.0/$injector/modulerr?p0=AppDj&p1=TypeError%…oogleapis.com%2Fajax%2Flibs%2Fangularjs%2F1.5.0%2Fangular.min.js%3A20%3A69)

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

AppDj.config(['$routeProvider', function($routeProvider, $locationProvider) {

   $routeProvider

    .when('/', {
        templateUrl: 'views/home.html',
        controller: 'mainCrtl'
    })

    .when('/login', {
        templateUrl: 'views/login.html'
    })

    .when('/register', {
        templateUrl: 'views/register.html'
    })

    .otherwise({
        redirectTo: '/'
    })

   $locationProvider.html5Mode(true);

}]);


AppDj.controller('mainCrtl', function ($scope){ 

});
1
  • Did you do this in your index.html: <script src="angular-route.js"> ?? Commented Feb 9, 2016 at 9:29

2 Answers 2

3

The error is thrown because Angular is trying to inject a module that it cannot find for some reason. Most likely this has nothing to do #. Make sure you include the script for the route provider in your page.

<script src="path/to/angular-route.js">

Edit: Actually, you haven't included the location provider, see this:

AppDj.config(['$routeProvider', '$locationProvider', function($routeProvider, $locationProvider)

Sign up to request clarification or add additional context in comments.

Comments

0

you haven't included the location provider, see this:

AppDj.config(['$routeProvider', '$locationProvider', function($routeProvider, $locationProvider)

Also do like below if you do not require a base tag

$locationProvider.html5Mode({
          enabled: true,
          requireBase: false
        });

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.