I'm trying to insert html into a child component. Basically something like this:
<custom-container><p>Parnet content</p></custom-container>
I can find references for passing data to child component but not able to find how to pass actual html inside my selector?
To let Angular know that a property in a child component or directive can receive its value from its parent component we must use the @Input() decorator in the said child. The @Input() decorator allows data to be input into the child component from a parent component.
You can also use <ng-content>
with select
attribute
Parent Component:
<child-component>
<div sample>Content form parent</div>
</child-component>
Child Component:
something..
<ng-content select="[sample]"></ng-content>
some more...
Output:
something..
<div>Content from parent</div>
some more...
More details here
ng-content tag can be used in the template of the child component. That tag will take in anything that you put in between your component selector.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With