Parse html from json


#1

Hello Ionics, I have a JSON with HTML tags. I want parse this input HTML to text for print on my app

I’m using this filter:

.filter('htmlToPlaintext', function() {
    return function(text) {
        return String(text).replace(/<[^>]+>/gm, '');
    }
});

and this my markup:

<p>{{noticia.texto | htmlToPlaintext}}</p>

but I have the result: “undefined”

anyone help me please?

Thanks in advance!


#2

I wrote a post about Filters with AngularJS and HTML parsing, maybe this can solve your problem: Using AngularJS Filters for HTML Parsing


#3

Hello @saimon! Thanks for your answer, nice tutorial, it works perfectly!

I have a more question:

My JSON request return:


<u><strong><a href=\"http://www.tecsidel.com\">Tecsidel</a></strong></u>


and your filter return:

http://www.tecsidel.com">Tecsidel

How I can modify your code for only show Tecsidel without lost the link?

Thanks so much!


#4

As you don’t need to replace anything, just remove the regex and replacement and your HTML should be displayed fine (works for me)!