0

I am having a text box which I am filling from the Json response as below

 <div class="gadget-body" style="height:100px">
    <label>{{ textData}}</label>
  </div>

But now my Json is returning html code with <p> and <h1> tags. I am binding the response, but it is displaying with <p> and <h1> tags instead of applying it.

6
  • Possible duplicate of Display HTML code in HTML Commented Jun 2, 2017 at 18:22
  • @ISHIDA removing space doesn't help Commented Jun 2, 2017 at 18:27
  • @Strernd I saw the link, but my case is different. I am using Angular2 and my Json response has html tags, which I need to convert and show it. Commented Jun 2, 2017 at 18:28
  • @phani1382 stackoverflow.com/questions/31548311/angular-2-html-binding Commented Jun 2, 2017 at 18:29
  • Give a id to your label and use innerHtml using that id and bind it. @techLove gave an example of it. Commented Jun 2, 2017 at 18:34

2 Answers 2

1

The simple and easiest way is use innerhtml tag

<div class="gadget-body" >
   <div [innerHTML]="textData">
</div>
  </div>
Sign up to request clarification or add additional context in comments.

Comments

0

Maybe have a function like this :

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

and then you'd use:

<div class="gadget-body" style="height:100px">
    <label>{{ htmlToPlaintext(textData) }}</label>
</div>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.