我正在尝试找出 Angular2 结构指令,目前,我无法发现 conditionaldiv
和 conditional之间的区别ng-template
。
从技术上讲,这段代码:
<div *ngIf="true">
<other-component></other-component>
</div>
将使用此代码执行相同的工作:
<ng-template [ngIf]="true">
<other-component></other-component>
</ng-template>
根据官方文档:“*星号是更复杂的东西的“语法糖”。在内部,Angular 将ngIf 属性转换为一个<ng-template>
元素,包裹在宿主元素周围。 “
Also, according to Angular University Blog : "Angular is already using ng-template under the hood in many of the structural directives that we use all the time: ngIf, ngFor and ngSwitch." (following the documentation above)
So, when it comes to write the statement in html, in simple words which is one is the proper one to render content conditionally and why. Any help is welcome!