1
votes

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){ 

});
2
Did you do this in your index.html: <script src="angular-route.js"> ?? - Charlie

2 Answers

3
votes

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)

0
votes

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
        });