Angularjs $location.search()不工作

Angularjs $location.search()不工作,angularjs,angular-ui,angular-ui-router,Angularjs,Angular Ui,Angular Ui Router,更新2: $location仅用于ng。 因此,$location.search是ng的搜索 它解析来自标记的url,如#或# 但是$window.location处理浏览器url 在我的问题中,第一个url的ng搜索是空的 第二个url的ng搜索是{code&state} 是这样吗 更新1: 我找到了*$窗口。位置*获得了正确的数据。 *$location*是否覆盖所有内容 问题 我在我的项目中使用angular ui router。我想从url获取搜索字符串, 像这样:http://loca

更新2:

$location仅用于ng。 因此,
$location.search
是ng的搜索 它解析来自标记的url,如##

但是
$window.location
处理浏览器url

在我的问题中,第一个url的ng搜索是空的 第二个url的ng搜索是{code&state}

是这样吗

更新1:

我找到了
*$窗口。位置*
获得了正确的数据。
*$location*
是否覆盖所有内容

问题 我在我的项目中使用angular ui router。我想从url获取搜索字符串, 像这样:
http://localhost:8080/?code=123456&state=auth#/api/oauth2_authorize
在app.config中,我设置:

我想搜索将是
{code:123456;state:auth}
,但不是。 我尝试将url更改为:
http://localhost:8080/#/api/oauth2_authorize?code=123456&state=auth
而且它起作用了

有人能告诉我为什么吗?HTML5模式为假。 我检查了angularjs的文档,并且$location的示例显示,我可以从url中获取搜索字符串。 我尝试使用$urlRouterProvider,但它仍然是空的


我能做什么?

因为,如果您将
HTML5模式设置为
false
,那么您的所有URL都需要有
。即使在url状态下,您也没有
#

因此
http://localhost:8080/?code=123456&state=auth#/api/oauth2_authorize
不起作用,并且
http://localhost:8080/#/api/oauth2_authorize?code=123456&state=auth
是的


检查
$location
和URL

我猜您使用的AngularJs版本有问题。 您使用的是哪个版本? 请参阅以下链接,建议使用HTML5Mode=true解决相同问题

或者只是浏览以下页面,可能有助于解决您的问题。


那么
$stateParams
呢?@PSL抱歉,它在第一个url处也是空的。第二个url工作。我想当你启用HTML5model true时它应该工作。你不能启用它吗?@MYN。。。谢谢你的帮助,但它不起作用…@GeminiYellow np,你没事吧?您的问题得到了回答?我尝试将html5mode设置为true,但ui.router的状态无法路由url。需要添加一些内容?@GeminiYellow您使用的URL是什么?给我举个例子。是从服务器接收的url。您好,您能告诉我如何在ui.router中获取非HTML5模型中的搜索对象吗。
$stateProvider.state("oauth2_authorize", {
            url: "/api/oauth2_authorize?code&state",
            template: "",
            controller: function($location) {
                       var search = $location.search();
            }
        })