ngsanitize - HTML encoded String not translating correctly in AngularJS -
i have html encoded string this:
sign , <span class="strong">something free!</span>
when use ngsanitize , ng-bind-html in template this:
<p ng-bind-html="sometext"></p>
i html decoded string:
sign , <span class="strong">something free!</span>
but literally shows html decoded string in browser, instead of rendering html correctly.
how can have render correct html in dom?
you can decode html string first. here's working plunker example.
angular.module('app', ['ngsanitize']) .controller('ctrl', ['$scope', '$sanitize', function($scope, $sanitize){ $scope.sometext = htmldecode("sign , <span class="strong">something free!</span>"); function htmldecode(input){ var e = document.createelement('div'); e.innerhtml = input; return e.childnodes.length === 0 ? "" : e.childnodes[0].nodevalue; } }]);
** decode function taken this answer.
Comments
Post a Comment