0

I have a div which renders HTML code currency:

<div [innerHtml]="item.Currency" title="" class="currTooltip"> <!-- This div 
                                            renders and show currency! -->  

    <div [innerHtml]="item.Currency" title="" class="tooltiptext"></div> <!-- This div
                                                          never rendered! -->   
</div>

item.Currency is equal to &#165;

What it is possible to see in DOM:

enter image description here

However, inside div never renders. What can I do to render inside div where there is a comment <!-- This div never rendered! -->?

2
  • 1
    Change innerHtml for innerHTML. Commented Feb 7, 2018 at 15:48
  • @ConnorsFan thanks, nevertheless it does not render. Commented Feb 7, 2018 at 15:56

1 Answer 1

3

You try to set the content of the outer div in two different ways at the same time. You include an inner div as its content and you also specify its innerHTML property. Only one of the two will be used (the one set with innerHTML, apparently). You should decide if the outer div contains the inner div, or if its content is provided by innerHTML.

If you want to have both, you can use one of these methods:

Method 1 - Include two inner elements:

<div title="" class="currTooltip">
  <span [innerHTML]="item.Currency" ></span>
  <div [innerHtml]="item.Currency" title="" class="tooltiptext"></div>
</div>

Method 2 - Include the entire inner div HTML inside of the innerHTML property of the outer div:

<div [innerHTML]="item.Currency + innerDivHtml" title="" class="currTooltip">
</div>

with innerDivHtml defined as a property getter:

get innerDivHtml(): string {
  return `<div title="" class="tooltiptext">${this.item.Currency}</div>`;
}
Sign up to request clarification or add additional context in comments.

2 Comments

please, see my updated question. I am so sorry for misleading you by conditions of task. I just wanted to simplify condition of task. Please, see my question again.
In any case, you cannot include the inner div inside of the outer one, and set innerHTML of the outer div at the same time, and expect to see both content.

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.