如何使用管道更改角度js中的url格式

时间:2015-04-09 08:15:05

标签: javascript angularjs

我的网址如下

http://localhost:9000/#/?name=angle,john,rechal&email=angle@gmail.com,john@gmail.com,rechal@gmail.com

如何更换或转换","用管#34; |"角度如下

http://localhost:9000/#/?name=angle|john|rechal&email=angle@gmail.com|john@gmail.com|rechal@gmail.com

1 个答案:

答案 0 :(得分:1)

请参阅下面的演示

string = string.replace(/,/g,'|')



var app = angular.module('app', []);

app.controller('homeCtrl', function($scope) {


  $scope.url = "http://localhost:9000/#/?name=angle,john,rechal&email=angle@gmail.com,john@gmail.com,rechal@gmail.com";
  $scope.aurl = $scope.url.replace(/,/g, '|')

});

<link href="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.1/css/bootstrap.min.css" rel="stylesheet" />
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>

<body>
  <div ng-app="app">
    <div ng-controller="homeCtrl">
      <pre>{{url}}</pre>
      <pre>{{aurl}}</pre>
    </div>
  </div>
</body>
&#13;
&#13;
&#13;