Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

AngularJS $locationProvider.html5mode() undefined

I am trying to use angular's $locationProvider.html5mode() to removed the "#" in URLs, but for some reason it always throws an error that html5mode is undefined. I tried logging $locationProvider in the console to inspect its properties and html5mode is present but when I try invoking it, it throws an error that its undefined. Has anyone experience this before and wouldn't mind shedding some light on what I am missing. Thanks in advance.

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

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

    $locationProvider.html5mode(true);        

    $routeProvider
        .when('/', {
            templateUrl: 'partials/home.html',
            controller: 'PageController'
        })
        .when('/app', {
            templateUrl: 'partials/app.html',
            controller: 'PageController'
        });

}]);
like image 793
Daniel Sandiego Avatar asked Nov 09 '14 13:11

Daniel Sandiego


1 Answers

You typed incorrect method name. Change

$locationProvider.html5mode(true);        

to

$locationProvider.html5Mode(true);        

with M uppercase in word mode.

like image 158
dfsq Avatar answered Sep 22 '22 15:09

dfsq