R
R
reus2019-06-18 18:35:04
Angular
reus, 2019-06-18 18:35:04

How to display nested divs in an element?

Hello. This is an Angular question. If I have two components: A (parent) and B (child)
And there is code like this:
A.html

<h1>Hello world!</h1>
<B>
  <div>
    <p>Element declarated from parent</p>
  </div>
</B>

Actually, how can I display in component B
what was delarated from the parent inside B, without creating a directive with a selector (since I want to display everything that was added to the component from the parent)?
For example, so that in the end component B looks like this:
B.html:
<div>
  <p>Hello from B</p>
  {{EmbededTags}}
</div>

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Dmitry Luzanov, 2019-06-18
@reus

NgContent? In general, I didn’t really understand anything from the question, but here it is:
a.component.html

<h1>Hello world!</h1>
<b-component>
  <div>
    <p>Element declarated from parent</p>
  </div>
</b-component>

b.component.html
<div>
  <p>Hello from B</p>
  <ng-content></ng-content>
</div>

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question