最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

angularjs - JavaScript how to replace %20 to space - Stack Overflow

programmeradmin3浏览0评论

I am trying to retrieve values from the url and displaying it in my web page using angular JS. what i am doing is

1) saving the entire url to a variable and split it so that i can filter to the value i need.

2) However when there is a space it is shown as %20. i want this %20 to be displayed as space itself.

Example : john doe is shown as john%20doe

Controller

function InboxController($scope, $http, $cookieStore, $location) {
    $scope.single_mail = function()
      { 
        var url = $location.url();
        var split_url = url.split('=');
        var mess_id = split_url[1];
        var from =  split_url[2];
        var id_value = mess_id.split('&');
        var inbox_id = id_value[0];
        var from_value = from.split('&');
        $scope.inbox_from = from_value[0];
        $scope.single_message = [];
        $scope.single_message = [];
        var single_inbox_mail =".html?contactid="+conId+"&token="+token+"&id="+inbox_id;
        $http.get(single_inbox_mail).success(function(response) {
        $scope.single_message = response[0];
       });

HTML view

<div class="page" data-ng-controller="InboxController">
  <div class="row" ng-init="single_mail()">
    <div class="mail-header row">
      <div class="col-md-8">
        <h3>{{single_message.subject}}</h3>
        <h4>From : <strong>{{inbox_from}}</strong></h4>
      </div>
    </div>
    <div class="mail-content">
      <p>{{single_message.body}}</p>
    </div>
  </div>
</div>

I am trying to retrieve values from the url and displaying it in my web page using angular JS. what i am doing is

1) saving the entire url to a variable and split it so that i can filter to the value i need.

2) However when there is a space it is shown as %20. i want this %20 to be displayed as space itself.

Example : john doe is shown as john%20doe

Controller

function InboxController($scope, $http, $cookieStore, $location) {
    $scope.single_mail = function()
      { 
        var url = $location.url();
        var split_url = url.split('=');
        var mess_id = split_url[1];
        var from =  split_url[2];
        var id_value = mess_id.split('&');
        var inbox_id = id_value[0];
        var from_value = from.split('&');
        $scope.inbox_from = from_value[0];
        $scope.single_message = [];
        $scope.single_message = [];
        var single_inbox_mail ="https://phoe.manage./app/inbox/message.html?contactid="+conId+"&token="+token+"&id="+inbox_id;
        $http.get(single_inbox_mail).success(function(response) {
        $scope.single_message = response[0];
       });

HTML view

<div class="page" data-ng-controller="InboxController">
  <div class="row" ng-init="single_mail()">
    <div class="mail-header row">
      <div class="col-md-8">
        <h3>{{single_message.subject}}</h3>
        <h4>From : <strong>{{inbox_from}}</strong></h4>
      </div>
    </div>
    <div class="mail-content">
      <p>{{single_message.body}}</p>
    </div>
  </div>
</div>
Share Improve this question edited Jan 8, 2015 at 10:07 Girish 12.1k3 gold badges36 silver badges53 bronze badges asked Jan 6, 2015 at 12:20 ShaSha 1,9746 gold badges35 silver badges60 bronze badges 0
Add a ment  | 

2 Answers 2

Reset to default 12

this is encoded url part, you should use decodeURIComponent() function and pass encoded string in first param, see sample code

decodeURIComponent("john%20doe");
//> john doe

try this using javascript ponent

var url = decodeURIComponent($location.url());
发布评论

评论列表(0)

  1. 暂无评论