danday74 danday74 - 2 months ago 9
AngularJS Question

angular trusting a url - to escape or not to escape

this angular filter works great but do i include the line encodeURI or not?
i.e. does angular $sce.trustAsResourceUrl do it for you? the docs are silent.

.filter('trustUrl', trustUrl);

trustUrl.$inject = ['$sce'];

function trustUrl($sce) {
return function (url) {
url = encodeURI(url); // <<<< NEEDED ?
return $sce.trustAsResourceUrl(url);


I think I left it in in the end since it didn't seem to cause any harm