如何在Angular2中使用ngIf而不使用额外的元素
为了在Angular 2+中使用*ngIf而不使用额外的元素,我们可以使用<ng-container>
或<ng-template>
但在许多情况下,<ng-container>
是推荐的。
以下是关于使用*ngIf而不使用额外元素的最佳方案。
app.component.ts:
app.component.html :
上述ng-container的代码说明
如果我们检查它,那么我们可以看到没有额外的元素添加在
<
div>标签和之前
标签。