NEB
NEB

Reputation: 734

Escaping the URL in the angularjs

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

In the above angular snippet, how to handle, when the value has / in it ? As it will be considered as a different url.

Upvotes: 1

Views: 35

Answers (1)

Immanuel Kirubaharan
Immanuel Kirubaharan

Reputation: 1094

Encode the value twice with encodeURIComponent which worked for me, you can try as shown below. And if you needs to get the value decode back then use decodeURIComponent twice as like encode function to do the revert.

Template:

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

Controller:

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

Upvotes: 1

Related Questions