![](/img/trans.png)
[英]How to render ng-template dynamically with Template Reference in Angular
[英]How to directly reference a block of html defined in ng-template in angular?
如何直接引用ng-template
定义的html块?
要引用filterOfDiv
,我必须使用*ngIf
指令,并且始终将条件设置为true
。
<ng-container *ngIf='true; then filterOfDiv'></ng-container>
<ng-template #filterOfDiv>
<div class="flex-column row-space filter-container">
<div>
<input type="checkbox" id="company1"><label for="company1" class="label-input">company1</label>
</div>
<div>
<input type="checkbox" id="company2"><label for="company2" class="label-input">company2</label>
</div>
</div>
</ng-template>
有没有一种方法可以直接引用filterOfDiv
,例如:
<ng-container filterOfDiv></ng-container>
只需使用NgTemplateOutlet指令
<ng-container *ngTemplateOutlet="filterOfDiv"></ng-container>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.