AngularJS:避免与$位置URL编码 [英] AngularJS: avoid url encoding with $location

查看:105
本文介绍了AngularJS:避免与$位置URL编码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我注意到,当我通过一个参数是一个数组$ location.search(),它是连接codeD如下面的例子

I notice that when I passed a parameter that is an array to $location.search(), it was encoded as in the following example

$ location.path('/ somePath')搜索('的ID [] ='[1,2,3]);

$location.path('/somePath').search('ids[]=', [1, 2, 3]);

变为

/ somePath DS%5B%5D = 1和; DS%5B%5D = 2及DS%5B%5D = 3

/somePath?ds%5B%5D=1&ds%5B%5D=2&ds%5B%5D=3

有没有办法避免URL编码?

Is there a way to avoid the url encoding?

推荐答案

对不起已故的答复,但我打一个类似predicament自己,以为我提供建议。

Excuse the late reply, but I struck a similar predicament myself and thought I'd offer advice.

在总之,如果你打算使用 $ location.search 你无法避免的URL为EN codeD。

In short, if you intend on using $location.search you cannot avoid the URL being encoded.

如果你看看在折角源, location.js 具体而言,你会发现,在函数返回组成的网址(即 LocationHtml5Url )的所有依靠另一个名为函数调用 toKeyValue ,它将连接code每当他们设置的所有键 - 值对。

If you take a look at the Angular source, location.js specifically, you'll notice that the functions return composed URLs (i.e. LocationHtml5Url) all rely on another function call named toKeyValue, which will encode all key-value pairs whenever they are set.

此外,在本例中使用的情况下,您所提供的,你不需要你的钥匙里的平等。当 $ location.search 被称为有两个参数,它们被视为由角一个键值对。

Furthermore, in the example use case you've provided, you don't need the equals inside your key. When $location.search is called with two parameters, they are treated as a key-value pair by Angular.

如果您需要使用的位置的URL就已经连接codeD之后,你可以随时调用<一个href=\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/de$c$cURIComponent\"相对=nofollow> 德codeURIComponent

If you need to make use of the location URL after it has been encoded, you could always call decodeURIComponent.

这篇关于AngularJS:避免与$位置URL编码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆