4

What is it called when one component is inside another? like in

<agm-map [latitude]="lat" [longitude]="lng">
  <agm-marker [latitude]="lat" [longitude]="lng"></agm-marker>
</agm-map>

And how it works?

2 Answers 2

7

You have to use ng-content

<ng-content></ng-content>
<ng-content select="agm-marker"></ng-content>

you have to declare two components as:

agm-map.component.ts

@Component({
    selector: 'agm-map',
    template: '<ng-content></ng-content>
            <ng-content select="agm-marker"></ng-content>'
})
export class AgmMapComponent {
  ...
}

agm-marker.component.ts

@Component({
    selector: 'agm-marker',
    template: '<div>Marker</div>'
})
export class AgmMarkerComponent {
  ...
}

But I guess you want to pass latitude/longitude to your child component for that you can read the documentation related to how to pass data from parent to child component here

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

Comments

0

I am fairly sure, that the middle component won't get rendered. It is an invalid sytax.

You can, however, create recursive component patterns with at least 2 different components, like this:

In a "recursion-container" component's html:

<agm-map ....

in agm-map component.html:

<recursion-container"...

So you basicly need a middle-layer for it.

On basic component communication, you can read the documentation

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.