应该在ng-template标记中使用ng-container。下面是一个示例:
在这个示例中,ngIf指令将会渲染ng-template标记,然后ng-container将会重复渲染给定的items数组,而custom-directive将会应用于每一个项。注意,我们没有使用ng-container作为ng-template标记的子元素,而是放在了ng-template标记内部。这样做可以在ngIf条件为false时阻止ng-container进行渲染。