1

Not sure if this is possible, but is there a way to do an *ngIf for ONLY the targeted element, without affecting anything inside?

For example, in the code below:

<div *ngIf="condition" class="outerDiv">
   <div class="innerDiv"></div>
</div>

if this condition is false, I would like it to still have:

<div class="innerDiv"></div>
Justin C.
  • 109
  • 1
  • 9

1 Answers1

2

No, it is not possible because HTML is structured like tree. If you delete higher branch, child branches are deleted as well.

I would suggest having wrappers for children and use ngIf else like answered over here: How to use *ngIf else?

EDIT:

Apparently, you can hide the parent using visiblity: hidden and set visibility: visible on the child. I'd recommend using ngClass and set classes based on conditions.

tsvedas
  • 1,049
  • 7
  • 18