0

I'm creating a front end application which looks at a database of Hearthstone cards allowing you to sort and search them. However, the Text displayed on the cards (Within the database) has HTML formatting within it such as <b> </b>

EG: The card "Toxic Arrow" has a text field containing:

Deal $2 damage to a minion. If it survives, give it <b>Poisonous</b>.

currently the rendering function looks as follows:

 `<tr *ngFor = "let card of cards">
     <td> {{card.text}} </td>
     <td> <img [src] = 'card.img'
         [title] = 'card.name'
         [style.width.px] = ImageWidth> </td>
  </tr> `

and currently the output within the table shows this: Deal $2 damage to a minion. If it survives, give it <b>Poisonous</b>.

I'm looking for a way to format this text quickly inside this loop to remove the $ and use the already existing HTML <b> tag

I'm not using the older AngularJs, I'm using the most current up to date version of Angular.

3
  • This has been answered many times, you will need to implement a pipe to allow the HTML (make it safe), check it here for instance: question Commented Nov 26, 2018 at 18:31
  • Thankyou i couldn't find any thing that made sense to me Commented Nov 26, 2018 at 18:34
  • use [innerHTML] to bind data. Commented Nov 26, 2018 at 18:35

1 Answer 1

4

You can replace the first <td> in your code with <td [innerHTML]="card.text"> </td>. This will cause the text to be displayed with HTML formatting as per the tags present in the input string.

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

2 Comments

But what if it was a <a> tag? I tried this it kinda works but it is not clickable.
it should work with proper formatting, check this

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.