【发布时间】:2018-06-18 10:33:08
【问题描述】:
我想知道使用 ng-template 的理想情况是什么。我有以下情况。代码如下所示
<div *ngIf="somecond">html inside1</div>
<div *ngIf="somecond1">html inside2</div>
<div *ngIf="somecond2">html inside3</div>
其他开发者修改如下
<ng-template #text1>html inside1</ng-template>
<ng-template #text2>html inside2</ng-template>
<ng-template #text3>html inside3</ng-template>
<div *ngIf="somecond;then text1"></div>
<div *ngIf="somecond1;then text2"></div>
<div *ngIf="somecond2;then text3"></div>
以上是使用ng-template 的正确方式或普通代码在这种情况下更好。我什么时候真正使用ng-template
【问题讨论】:
标签: angular ng-template