2016-08-02 53 views
1

我正在寻找使用$ locationProvider api在我的项目中更改为html5mode。我如何将它注入指令?这是我现在有:

angular 
.module('myApp') 
.directive('errorModal', ['$location', , 
function($location, $locationProvider) { 
    //to expose locationProvider to the window 
    window.provider = $locationProvider; 
} 

但是,这给了locationProvider是未定义的。这里适当的语法是什么?

回答

1

我想你必须尝试以这种方式:

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

app.config(function($locationProvider) { 
    $locationProvider.html5Mode(true); 
}); 

app.controller('myCtrl', function($location) { 
    $location.path('/my/path'); 
}); 

进样$ locationProvider在配置和$位置控制器/指令