Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Where is the online official documentation about <ng-content> tag in Angular2?

Tags:

angular

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?

like image 856
niaomingjian Avatar asked Dec 02 '16 08:12

niaomingjian


People also ask

What is Ng-content tag?

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.

What is Ng-content tag in angular?

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.

Can we style 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.

What is Ng container ng-content ng template?

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.


Video Answer


2 Answers

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.

like image 171
Isaac Kbn Avatar answered Oct 25 '22 15:10

Isaac Kbn


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.

like image 31
wuno Avatar answered Oct 25 '22 15:10

wuno