javascript - AngularJs: How to decode HTML entities in HTML? -


the situation:

i bulding webpage content taken calling api returns data in json format.

the problem html tags given html entities, has decoded.

example:

this example of json dealing with:

<p align="justify"><strong>15<sup>th</sup> here there bold text </strong> here normal text... 

attempt:

i have spend time research , seems harder thought. looking in google , similar question, possible solution use ng-bing-html

api call:

$http.get('http://api/page_content').then(function(resp)  {     $scope.content_test = resp.data[0].content;  } 

filter:

.filter('trusted', ['$sce', function($sce){     return function(text) {         return $sce.trustashtml(text);     }; }]) 

ng-bind-html in angular view:

<div ng-bind-html=" content_test  | trusted"></div> 

output:

this output in view (exactly see it):

<p align="justify"><strong>15<sup>th<\/sup> here there bold text<\/strong> here normal text... 

but need see text formatted:

here there bold text here normal text...

the question:

how can decode html entities in proper formatted html in angularjs?

i think need perform 1 more "decoding" step before pass $sce. example this:

app.filter('trusted', ['$sce', function($sce) {     var div = document.createelement('div');     return function(text) {         div.innerhtml = text;         return $sce.trustashtml(div.textcontent);     }; }]); 

demo: http://plnkr.co/edit/lrt4tgyttu4cproaidra?p=preview


Comments

Popular posts from this blog

toolbar - How to add link to user registration inside toobar in admin joomla 3 custom component -

linux - disk space limitation when creating war file -