문제

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

도움이 되었습니까?

해결책

$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

다른 팁

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>
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top