Justin C.
Justin C.

Reputation: 109

*ngIf to toggle parent div without affecting the child

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>

Upvotes: 1

Views: 1703

Answers (1)

tsvedas
tsvedas

Reputation: 1069

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.

Upvotes: 2

Related Questions