Javascript 角度:更换过滤器并完成相对<;a href="/&引用&燃气轮机;路径

Javascript 角度:更换过滤器并完成相对<;a href="/&引用&燃气轮机;路径,javascript,angularjs,angular-directive,angular-filters,Javascript,Angularjs,Angular Directive,Angular Filters,我是angular的新手,我正在努力替换文本中的相对href路径 例如,我有以下控制器/scope/html/filter: $scope.text = 'Here you can find the best <a href="/shoes/sport">sport shoes</a>, <a href="/shoes/classic">classic shoes</a> and <a href="/socks/sale">socks&

我是angular的新手,我正在努力替换文本中的相对href路径

例如,我有以下控制器/scope/html/filter:

$scope.text = 'Here you can find the best <a href="/shoes/sport">sport shoes</a>, <a href="/shoes/classic">classic shoes</a> and <a href="/socks/sale">socks</a>. If not, you can <a href="http://www.google.com">google</a> it.';

<p ng-bind-html="text | parseUrlFilter"></p>
但是,我的过滤器只替换每个模式的第一个case()

是否有人知道我如何使其工作良好并替换所有匹配和模式,或者是否有其他更聪明/更聪明的方法来获得我需要的

PS:这个angular项目是一个Ionic平台(移动应用程序),我正在从一个与桌面版本(php)共享的数据库中检索数据(文本+链接),该版本通常插入这些相对路径。因此,我需要完成它们,否则我的移动应用程序中的许多链接将被破坏


谢谢你的帮助

您可以尝试使用正则表达式。诸如此类:

var str = 'Here you can find the best <a href="/shoes/sport">sport shoes</a>, <a href="/shoes/classic">classic shoes</a> and <a href="/socks/sale">socks</a>. If not, you can <a href="http://www.google.com">google</a> it.';
var res = str.replace(/href=\"\//g, "href=\"http://www.example.com/");
var str='在这里您可以找到最好的,并且。如果没有,你可以这样做。”;
var res=str.replace(/href=\“\//g,“href=\”http://www.example.com/");

正则表达式中的“g”是一个全局替换。

您不必从头开始实现它!你应该检查有角度的路线。Hi@EiriniGraonidou问题是这个angular项目是一个Ionic平台(移动应用程序),我正在从一个与桌面版本(php)共享的数据库中检索数据(文本+链接),该版本通常插入这些相对路径。所以我需要填写它们,否则我的应用程序中的所有链接都将被破坏。谢谢!我的案子做得很好!
var str = 'Here you can find the best <a href="/shoes/sport">sport shoes</a>, <a href="/shoes/classic">classic shoes</a> and <a href="/socks/sale">socks</a>. If not, you can <a href="http://www.google.com">google</a> it.';
var res = str.replace(/href=\"\//g, "href=\"http://www.example.com/");