0

I have a user-configurable layout where I believe I would need to change nesting of elements per configuration. I don't want multiple templates, as this would be a chore to maintain, but I would like to know if there is some way in Angular 2 to define a parent element whose child elements will display weather or not the parent element is displayed. So if I have:

<parent>
    <child />
</parent>

I would like to use some sort of toggle to remove the parent element from the display list without losing it's child. So upon toggling off, child would become a child of parent's parent.

Is that even possible?

3
  • Are you talking about the classes specifically, or components with view-children? Commented Jan 25, 2017 at 19:03
  • I will answer with a different approach if you actually need to remove that parent element from the DOM. Commented Jan 25, 2017 at 19:08
  • I have updated the question to clarify. I am not trying to toggle the class, but rather remove the parent element without losing its children. Commented Jan 25, 2017 at 20:15

1 Answer 1

1

Editing to match the new question:

I'm not aware of any option to allow you to this easily. A simple solution that may not be comprehensive enough for your application:

<parent *ngIf="parentCondition">
    <child />
</parent>
<child *ngIf="!parentCondition" />
Sign up to request clarification or add additional context in comments.

1 Comment

Brilliant. Thank you!

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.