如何解决AngularJS中的“ TypeError:$ location.absUrl不是函数”错误

时间:2019-02-06 19:03:27

标签: javascript angularjs angular-ui-router angular-routing

我正在使用旧版AngularJS应用程序,目前刚升级到AngularJS 1.7.6。该应用程序使用ui-router,在angular.module().config中,我们有一些使用$location.absUrl.的代码

我知道$location无法以正常方式注入到module.config中,因此我们正在使用ui-router网站上建议的$injectorhttps://github.com/angular-ui/ui-router/wiki/URL-Routing

但是,$location.absUrl总是在标题上返回上述错误。根据AngularJs文档,Angular 1.7.6仍支持$location.absUrl。我希望有人能指出正确的方向。

$urlRouterProvider.otherwise(function ($injector, $location){
        var url = $location.absUrl();            

        if (url.indexOf('/admin') !== -1) {
            $location.path("/admin");
        }
        else {
            $location.path("home");
        }
    });

0 个答案:

没有答案