I came across <ng-content>
in Angular2 application.
I can't find any documentation here.
Where is the online official documentation about <ng-content>
tag in Angular2?
The ng-content tag is used for content projection. It is basically a placeholder to hold the dynamic content until it is parsed. Once the template is parsed, Angular replaces the tag with content.
The ng-content is used when we want to insert the content dynamically inside the component that helps to increase component reusability. Using ng-content we can pass content inside the component selector and when angular parses that content that appears at the place of ng-content.
Use the :host /deep/ selector. If you want to use the shadow DOM polyfill and style your components using the style or styleUrls attribute of the Component decorator, select the element with :host , then ignore the shadow DOM polyfill with the /deep/ child selector. :host will select the element.
To sum up, ng-content is used to display children in a template, ng-container is used as a non-rendered container to avoid having to add a span or a div, and ng-template allows you to group some content that is not rendered directly but can be used in other places of your template or you code.
There is currently no page for <ng-content>
in the official Angular documentation, though you can find a short mention of it within the guide for Content projetion, where it says:
The
<ng-content>
tag is a placeholder for the external content. It tells Angular where to insert that content.
It is a known issue that the ngcontent class
is not documented. Many people have searched and not found it. You can find plenty of people complaining about this on Redit.
Although there are many references of ngcontent
in the docs. For example on this page.
Docs for ngcontent
examples ng-content
These are the styles we wrote, post-processed so that each selector is augmented with _nghost or _ngcontent attribute selectors. These extra selectors enable the scoping rules described in this guide.
An element within a component's view has a _ngcontent attribute that identifies to which host's emulated Shadow DOM this element belongs.
I think you are searching for ng-content
. So search for ngcontent
and you will find information and examples using the ngcontent class
.
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