ng-container in Angular

ng-container is a logical container tag that can be used as a group node. It will not be rendered into DOM, but will be parsed as HTML Comment.

as

<div><ng-container>foo</ng-container><div>

will output:

<div><!--template bindings={}-->foo
<div>

So when you want to use *ngIF or *ngFor , you don't want to use semantic tags, you can use ng-container.

<div><ng-container *ngIf="true"><h2>Title</h2><div>Content</div></ng-container></div>

which is

<div><h2>Title</h2><div>Content</div></div>

 

 

 

 

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326627107&siteId=291194637