AngularJs Error Remove # URL

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

});

Answers


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)


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

Need Your Help

How to open a pdf file using jquery and phonegap in android?

android jquery pdf cordova

Recently I am building an application for android. I am using phonegap to do the same. Everything is running fine except one problem i.e. I cant open a pdf file using jquery in android. I have trie...

Zend_Dojo_Form not rendering in layout

zend-framework dojo zend-form

I have a quick question about adding Zend_Dojo_Form into Zend_layouts.