Javascript 如何修改hashbang url的角度

Javascript 如何修改hashbang url的角度,javascript,angularjs,Javascript,Angularjs,我正在尝试添加一个#!到路线而不是#。(/#/ --> /#!/). 但是,当我试图修改$location时,我遇到了一个错误:(未知提供者:$location from myApp) app.js文件 'use strict'; // Declare app level module which depends on filters, and services var myApp = angular.module('myApp', ['myApp.filters', 'myApp.serv

我正在尝试添加一个#!到路线而不是#。(/#/ --> /#!/). 但是,当我试图修改$location时,我遇到了一个错误:(未知提供者:$location from myApp)

app.js文件

'use strict';


// Declare app level module which depends on filters, and services
var myApp = angular.module('myApp', ['myApp.filters', 'myApp.services', 'myApp.directives', 'myApp.controllers']);

myApp.config(['$routeProvider',
    function($routeProvider) {
        $routeProvider.when('/home', {templateUrl: 'partials/home.html', controller: 'HomeController'});
        $routeProvider.when('/results', {templateUrl: 'partials/results.html', controller: 'ResultsController'});
        $routeProvider.when('/print/:param1', {templateUrl: 'partials/print.html', controller: 'PrintController'});
        $routeProvider.when('/results/:param1', {templateUrl: 'partials/results.html', controller: 'ResultsController'});

        $routeProvider.otherwise({redirectTo: '/home'});
  }]);

//enable hashbang (#!) url for google SEO
myApp.config(['$location', function($location) {
        $location.hashPrefix('!');
    }]);

您需要使用提供程序(
$locationProvider
)来配置服务(
$location


@WilliamFalcon它变得更容易,而且值得。
myApp.config(['$locationProvider', function($locationProvider) {
     $locationProvider.hashPrefix('!');
}]);