25

I am working with the rich text editor component of primeng. This editor turns everything i type in into html. But sometimes i want to output these texts in plain text instead. Does angular 2 provide a way to easily remove the html tags from the text?

Thank you.

0

1 Answer 1

62

You can achieve this by JavaScript.

Try this!!

var plainText = content.replace(/<[^>]*>/g, '');

This will return you plain text.

Sign up to request clarification or add additional context in comments.

3 Comments

Great. I just replaced the coincidences by ` ` because my text is full of line breaks and <ul> tags
This will fail if there is a close angle bracket inside an attribute or a comment.
This answer really helped me with SharePoint rich text columns. There is a lot of garbage markup in there, and it's hard to determine if empty.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.