之间有什么区别
<ng-container *ngIf="flag">
<child-component></child-component>
</ng-container>
或直接
<child-component *ngIf="flag"></child-component>
最佳做法是什么?
ng-container
是Angular未加载到DOM中的指令。它的功能是将其他指令组合在一起。在这种情况下,ngIf
它用于将所有都依赖于同一标志的不同元素组合在一起。
<ng-container *ngIf="flag">
<div>1</div>
<div>2</div>
...
</ng-container>
如果只有一个元素,则无需进行太多分组,可以*ngIf
直接将其放置在元素上。
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句