Question

I am trying to remove the hash tag from the url in angularJS. From the research I found that I need to use $locationProvider but I can not figure out which dependency is required to get this working!

This is my angular code

angular.module('airlineApp', [
  'ngCookies',
  'ngResource',
  'ngSanitize',
  'ngRoute'
]).config(function($routeProvider, $locationProvider) {

    $routeProvider
      .when('/testing', {
        templateUrl: 'views/main.html',
        controller: 'MainCtrl'
      })
      .otherwise({
        redirectTo: '/'
      });
    $locationProvider.html5Mode(true);
  });

That does not work, I'm assuming it's because I don't have locationProvider.

I am using the angular engine in bower to help with dependency instalments. So for locationProvider I tried

bower install --save locationProvider

That doesn't exist, I also search in the bower Search Bower Packages section and can't find anything useful.

I'm just starting with angular so it might be that the problem is elsewhere. Do you know what's going on?

Thanks

Était-ce utile?

La solution

$locationProvider must work from box

try use another for for injector

angular.module('airlineApp', [
  'ngCookies',
  'ngResource',
  'ngSanitize',
  'ngRoute'
]).config(['$routeProvider', '$locationProvider', function($routeProvider, $locationProvider) {

    $routeProvider
      .when('/testing', {
        templateUrl: 'views/main.html',
        controller: 'MainCtrl'
      })
      .otherwise({
        redirectTo: '/'
      });
    $locationProvider.html5Mode(true);
  }]);

if possible - give a value that got your module by name $locationProvider or show exxample at jsbin

Autres conseils

1) Are you getting an specific error message on console?

2) Be sure to include the .js files, like

<script src="bower_components/locationProvider"></script>
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top