角度网址加号转换为空格 [英] Angular url plus sign converting to space

查看:24
本文介绍了角度网址加号转换为空格的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有角度应用程序,我想在查询字符串中传递加号 + ,例如:

I have angular application where i want to pass plus sign + in query string like:

http://localhost:3000/page?name=xyz+manwal

当我点击这个 URL 时,它会转换为:

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屋!

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