Search code examples
angularinnerhtmlangular-ng-if

InnerHTML *ngIf does not work Angular5


To show a pop up on a GIS openlayers map i use the InnerHtml attribute. If a field is false I want to hide is DIV.

It looks like angular ignores my ngif this is my code:

this.content.innerHTML = `
      <div style="width: 150px; float: right; font-size: 13px;" *ngIf="!test">
              ${ test } 
      </div> `

My boolean test is false. Is it true that ngIf does niet work with innerHTML?

thx al lot


Solution

  • Angular will not entertain your *ngIf when you are using innerHTML

    Whenever you pass some content via innerHTML, Angular is just going to render that content does not evaluate any expression or binding within that content like you did by adding a ngIf event.