Search code examples
angulartagsmailto

How to parse HTML content that is coming from angular JSON response


[![enter image description here][1]][1]I am using the below mailto Code to populate to, cc, bcc, subject and body fields in email application. I am binding the parameters that is coming from JSON response as below. In the below code, contentField I am getting from response as HTML code with some
tags. I need to remove the br tags and populate the fields in next line .

<a class="" href="mailto:{{toField}}?cc={{ccField}}&bcc={{bccField}}&subject={{subjectField}}&body={{contentField}}

Below is the HTML code from response and I am binding that to content in HTML.

'Please H F LUI DIGESTIVE AND LIVER CLINIC and +65 90119103 <br> 
Issues: </br><br>Doctor</br>MCR: 05572G'

What I want to achieve is :

'Please H F LUI DIGESTIVE AND LIVER CLINIC and +65 90119103
Issues:

Doctor MCR: 05572G'


Solution

  • You can parse HTML content using the below Regex as well.

    // cleanText = strInputCode.replace(/<\/?[^>]+(>|$)/g, "");
       cleanText = strInputCode.replace(/<.*?br.*?>/g, '%0D%0A');
    

    JavaScript: How to strip HTML tags from string?