Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

component inside component Angular

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?

like image 391
Pedro Cova Avatar asked Oct 28 '25 19:10

Pedro Cova


1 Answers

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

like image 153
Anshuman Jaiswal Avatar answered Oct 30 '25 18:10

Anshuman Jaiswal