1
- import { Component , DestroyRef , inject , OnInit } from '@angular/core' ;
1
+ import { Component , computed , contentChildren , DestroyRef , inject , OnInit , TemplateRef } from '@angular/core' ;
2
2
3
3
import { CarouselState } from '../carousel-state' ;
4
4
import { CarouselService } from '../carousel.service' ;
5
5
import { takeUntilDestroyed } from '@angular/core/rxjs-interop' ;
6
+ import { NgTemplateOutlet } from '@angular/common' ;
7
+ import { TemplateIdDirective } from '../../shared' ;
6
8
7
9
@Component ( {
8
10
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' }
10
15
} )
11
16
export class CarouselIndicatorsComponent implements OnInit {
12
17
readonly #destroyRef = inject ( DestroyRef ) ;
@@ -16,6 +21,18 @@ export class CarouselIndicatorsComponent implements OnInit {
16
21
items : ( number | undefined ) [ ] = [ ] ;
17
22
active = 0 ;
18
23
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
+
19
36
ngOnInit ( ) : void {
20
37
this . #carouselService. carouselIndex$ . pipe ( takeUntilDestroyed ( this . #destroyRef) ) . subscribe ( ( nextIndex ) => {
21
38
this . items = this . #carouselState?. state ?. items ?. map ( ( item ) => item . index ) ?? [ ] ;
0 commit comments