1- import { Component , DestroyRef , inject , OnInit } from '@angular/core' ;
1+ import { Component , computed , contentChildren , DestroyRef , inject , OnInit , TemplateRef } from '@angular/core' ;
22
33import { CarouselState } from '../carousel-state' ;
44import { CarouselService } from '../carousel.service' ;
55import { takeUntilDestroyed } from '@angular/core/rxjs-interop' ;
6+ import { NgTemplateOutlet } from '@angular/common' ;
7+ import { TemplateIdDirective } from '../../shared' ;
68
79@Component ( {
810 selector : 'c-carousel-indicators' ,
9- templateUrl : './carousel-indicators.component.html'
11+ exportAs : 'cCarouselIndicators' ,
12+ imports : [ NgTemplateOutlet ] ,
13+ templateUrl : './carousel-indicators.component.html' ,
14+ host : { class : 'carousel-indicators' }
1015} )
1116export class CarouselIndicatorsComponent implements OnInit {
1217 readonly #destroyRef = inject ( DestroyRef ) ;
@@ -16,6 +21,18 @@ export class CarouselIndicatorsComponent implements OnInit {
1621 items : ( number | undefined ) [ ] = [ ] ;
1722 active = 0 ;
1823
24+ readonly contentTemplates = contentChildren ( TemplateIdDirective , { descendants : true } ) ;
25+
26+ readonly templates = computed ( ( ) => {
27+ return this . contentTemplates ( ) . reduce (
28+ ( acc , child ) => {
29+ acc [ child . id ] = child . templateRef ;
30+ return acc ;
31+ } ,
32+ { } as Record < string , TemplateRef < any > >
33+ ) ;
34+ } ) ;
35+
1936 ngOnInit ( ) : void {
2037 this . #carouselService. carouselIndex$ . pipe ( takeUntilDestroyed ( this . #destroyRef) ) . subscribe ( ( nextIndex ) => {
2138 this . items = this . #carouselState?. state ?. items ?. map ( ( item ) => item . index ) ?? [ ] ;
0 commit comments