How to display html tags as plain text in angular
I'm developing a blog using Angular. There I want to show HTML string retrieved from the database as plain text (for listing each blog post's preview). The HTML rich-text was generated using Show I can able to render the rich text by using the code How can I do this in an
Do Nhu Vy 41k47 gold badges181 silver badges254 bronze badges asked Jun 22, 2020 at 1:43
2 i don't know about quill.. so may be there will be another good solution i think you can solve this problem with pipe something like this
if you don't wanna use in template just return that value and use it i hope it helps answered Jun 22, 2020 at 5:38
1 I think you can use
I used it before also with Quill answered Jun 22, 2020 at 7:13
3 Basically, there are two methods for displaying HTML tags as plain text. 1. Using 2. HTML entities: The second and only option available is using html entities. < ,> are reserved characters in HTML, In order to display this reserved characters you have to replace them with html entities. You can learn more about entities here. You can either use entity name or entity number initializing them with & and ending them with ; Refer to below table for required html entities:
Example 1: In the first example, we are using html entity names to display body element and paragraph element on web page. HTML
Output: Output Explanation: In above code, “<” and “>” is simply replaced by their respective html entities. is html element which defines preformatted text. Example 2: In below example, we are trying to display html entity name for “<” using entity name for “&” sign. HTML
Output: Output Explanation: In above example, “&” is replaced with “&” and “<“ is replaced with “<” How do I render a string with HTML tag in angular 8?To render a html string in angular, we can use the innerHTML property by binding a string to it. The innerHTML property sanitizes the html, so that your app is safe from the cross-site scripting attacks(XSS).
How do I display HTML code without executing?Use HTML Special Character Codes
var myCode = "This is not bold"; $('span#code-span'). text(myCode); Using text instead of html will cause tags to be rendered exposed instead of being executed.
How do I convert typescript to plain text in HTML?var text = html. replace(/<\/?[^>]+>/gi, ' '); The problem with the above approach is that it may fail for malformed HTML or when the HTML content contains entities like dashes, ampersands and other punctuation codes.
How do I view the HTML code of a website?To view only the source code, press Ctrl + U on your computer's keyboard. Right-click a blank part of the web page and select View source from the pop-up menu that appears.
|