假设我有以下代码使用AngularJs:
angular.module('somename', []).
config(function ($routeProvider, $locationProvider) {
$routeProvider.
when('/test/:userid', { controller: TestDataCtrl }).
when('/users/:userid', {controller: UserDataCtrl}).
otherwise({redirectTo: '/index.html'});
$location.path('/newValue')
});
但是这个片段引发了ReferenceError:$ location不是从archivarius定义的。好的,没问题。我在函数中添加了第三个参数$ location并出现错误 - 未知提供者:来自archivarius的$ location。
那么,我怎样才能获得$ location服务的实例?
换句话说,我有一些丑陋的网址:
http://localhost:7000/myservice/1?html=true#/index
我上面的路线不起作用,因为它应该是 服务网址看起来像
http://localhost:7000/myservice/#/index
or
http://localhost:7000/myservice/index
但是由于我的REST服务的内部重定向逻辑,我提出了 对AngularJs来说有点令人困惑的网址,我需要在没有页面重新加载的情况下更改它。
提前致谢。
答案 0 :(得分:0)
添加`$ location'对象为你配置一致的功能:
config(function ($routeProvider, $locationProvider, $location)
希望有所帮助