角网址加号转换为空间 [英] Angular url plus sign converting to space
本文介绍了角网址加号转换为空间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有角度应用程序,我想在查询字符串中传递加号 + ,如:
I have angular application where i want to pass plus sign + in query string like:
http://localhost:3000/page?name=xyz+manwal
当我点击这个其转换为以下网址:
When I am hitting this URL its converting to:
http://localhost:3000/page?name=xyz%20manwal
其中%20 是指空格
。我该如何阻止这种转换?
Where %20 refer to space . How can I prevent this conversion?
推荐答案
我找到了解决方案并将其发布以供将来参考。 Angular js将 +
转换为%2B
。
I have found solution and posting it for future reference. Angular js was converting +
sign into %2B
.
以下代码阻止了:
.config([
'$provide', function($provide) {
$provide.decorator('$browser', function($delegate) {
let superUrl = $delegate.url;
$delegate.url = (url, replace) => {
if(url !== undefined) {
return superUrl(url.replace(/\%2B/g,"+"), replace);
} else {
return superUrl().replace(/\+/g,"%2B");
}
};
return $delegate;
});
}
])
这篇关于角网址加号转换为空间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文