0

I need to display the full generated content of a component some where else in the html dom (although within the app-root).

Let me explain.

I have this code in app.component.html

<app-component-one></app-component-one>
<app-component-two></app-component-two>

Now app-component-two calls another component in it conditionally, like this:

<app-component-three *ngIf="show3"></app-component-three>

Now what it will do is that it will show the app-component-three data/html inside app-component-two. But for some reason I want that data/html to be placed/shown inside the app-component-one.

Is that possible?

EDITS

Use Case 1: app-component-one is on the left half of screen, app-component-two is on the right half. Some formatted and bound data is generated in app-component-two but I want to show it on the left side of the screen, not on right side where it was actually generated.

Use Case 2: app-component-one is outside all bounds and router-outlet, while app-component-two is actual app which generates reports. If the report is kept in there, it is not rendered properly. So I need to pull it out of the app-component-two component and its position: fixed css bounds.

6
  • Can you not simply put app-component-three inside app-component-one? and display it inside app-component-one based on some condition in app-component-two? Commented May 15, 2020 at 20:44
  • Please see the edits I made to the post to define it more. Commented May 15, 2020 at 20:46
  • @AshishRanjan your idea makes sense, it will need indirection in code using data service, but it is workable. If there was some default practice in Angular that any expert like yourself knows, it will be highly appreciated. Commented May 15, 2020 at 20:48
  • Yeah, In both the cases, whatever data is needed for app-component-three, you generate that in app-component-two and pass it to app-component-one Commented May 15, 2020 at 20:49
  • I would say, having a shared service should do. Commented May 15, 2020 at 20:50

1 Answer 1

1

IMO, instead of first rendering DOM and then plucking it to display somewhere else, the approach should be to keep app-component-three inside app-component-one itself.

It's just that app-component-one needs to know when should it render its new child, we can pass that information and any other data if required from app-component-two through a shared service. The Shared service may have an Observer/Observable which app-component-two publishes and app-component-one subscribes.

Sign up to request clarification or add additional context in comments.

Comments

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.