구성 요소 내에 모든 템플릿 (TemplateRef)의 컬렉션을 얻으려면 어떻게해야합니까? 그것은 ViewChild와 잘 작동하지만 ViewChildren은 정의되어 있지 않습니다 ...<template> 요소에 대해 @ViewChildren (TemplateRef)이 정의되지 않았습니다.
나는이 question에서 해결책을 사용합니다. Plunker 전체 예제가 있습니다.
@Component({
selector: 'my-app',
template: `
<div>
<template #model>...</template>
<template #color>...</template>
</div>`
})
export class App {
@ViewChild('model') model;
@ViewChild('color') color;
@ViewChildren(TemplateRef) templates: QueryList<TemplateRef>;
ngAfterContentInit() {
console.log(this.templates); // undefined
console.log(this.model); // TemplateRef_ {...}
}
}
가 나는 열에 대한 템플릿을 정의하는 것이 가능 그리드 구성 요소에 대한 templates
이 필요합니다. 불행히도 ng 콘텐츠 doesn't support 동적 투영, 그래서 그것을 템플릿으로 달성하려고 해요.