I updated my project to the latest angular2 4.0.0-rc.5 and upon building it spits a lot of warnings like this:
Template parse warnings:
The <template> element is deprecated. Use <ng-template> instead ("_newGroupReward.group.description}}
My question is - what is and where can I find info about it and how to use it ? I have been googling however the only doc I could find is about the stable 2.4.x versions ( official docs ).
Best regards
ng-template is an Angular element that is used for rendering HTML in a template. However, it is not rendered directly on DOM. If you include an ng-template tag to a template, the tag and the content inside it will be replaced by comment upon render.
ng-template is used to render HTML in a template but is never rendered directly. If you add a ng-template tag to your template, it and everything inside it will be replaced by a comment. It might seem a bit useless, but it is rarely used alone. It can be for example used to define the else case of an *ngIf.
ng-container serves as a container for elements which can also accept structural directives but is not rendered to the DOM, while ng-template allows you to create template content that is not rendered until you specifically (conditionally or directly) add it to the DOM.
Structural Directives are directives which change the structure of the DOM by adding or removing elements. There are three built-in structural directives, NgIf , NgFor and NgSwitch . These directives work by using the HTML 5 <ng-template> tag.
ngTemplate is a replacement for template, It is used when a sample template should be injected into the DOM.
The below example is illustrated with using ngIf else
as below,
<ng-template #loading>Failed to do something wrong...</ng-template>
<div *ngIf="userObservable;else loading;">
Aravind is here
</div>
When I am using loading, angular calls the TemplateRef with the name as loading
denoted by #loading
and respective template is replaced inside the div.
LIVE DEMO
Documentation link
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