Can someone please illustrate the difference between using
and
elements?
I could not find document
ng-template
The
is an Angular element for rendering HTML. It is never displayed directly. Use for structural directives such as: ngIf, ngFor, ngSwitch,..
Example:
{{hero.name}}
Angular translates the *ngIf attribute into a
element, wrapped around the host element, like this.
{{hero.name}}
ng-container
Use as a grouping element when there is no suitable host element.
Example:
Pick your favorite hero
()
This will not work. Because some HTML elements require all immediate children to be of a specific type. For example, the element requires children. You can't wrap the options in a conditional or a
.
Try this :
Pick your favorite hero
()
This will work.
More information: Angular Structural Directive