逃脱了Angularjs中的URL



<a ng-href="#/abc/{{ value }}/xyz">{{ value }}</a>

在上面的角段中,当value中有/时,如何处理?因为它将被视为不同的URL。

encodeuricomponent 对值进行编码,对我有用,您可以尝试如下所示。而且,如果您需要重新解码值,请使用 decodeuricomponent 两次,就像编码函数以进行恢复。

模板:

<a ng-href="#/abc/{{ encodeTwice(value) }}/xyz">{{ value }}</a>

控制器:

$scope.encodeTwice=function(value){
   return encodeURIComponent(encodeURIComponent(value));
}

最新更新