我试图从url检索值,并使用角度的JS在我的网页中显示它.我在做什么是
1)将整个URL保存到变量中,并将其拆分,以便我可以过滤到我需要的值.
示例:john doe被显示为john doe
调节器
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.com/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视图
<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>
解决方法
这是编码的url部分,应该使用
decodeURIComponent()
函数,并在第一个参数中传递编码的字符串,请参阅示例代码
decodeURIComponent("john%20doe"); //> john doe