Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit bd18c53

Browse filesBrowse files
committed
feat(carousel-indicators): allow custom content via TemplateId directive, refactor
1 parent d8c0f4e commit bd18c53
Copy full SHA for bd18c53

File tree

Expand file treeCollapse file tree

2 files changed

+24
-4
lines changed
Filter options
Expand file treeCollapse file tree

2 files changed

+24
-4
lines changed
+5-2Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1-
<div class="carousel-indicators">
1+
@let tmpl = templates();
2+
<ng-container *ngTemplateOutlet="tmpl['carouselIndicatorsTemplate'] || defaultCarouselIndicatorsTemplate; context: {$implicit: items, active: active}" />
3+
4+
<ng-template #defaultCarouselIndicatorsTemplate>
25
@for (item of items; track item; let i = $index) {
36
<button
47
[attr.data-coreui-target]="i"
@@ -8,4 +11,4 @@
811
[attr.aria-current]="active === i">
912
</button>
1013
}
11-
</div>
14+
</ng-template>

‎projects/coreui-angular/src/lib/carousel/carousel-indicators/carousel-indicators.component.ts

Copy file name to clipboardExpand all lines: projects/coreui-angular/src/lib/carousel/carousel-indicators/carousel-indicators.component.ts
+19-2Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,17 @@
1-
import { Component, DestroyRef, inject, OnInit } from '@angular/core';
1+
import { Component, computed, contentChildren, DestroyRef, inject, OnInit, TemplateRef } from '@angular/core';
22

33
import { CarouselState } from '../carousel-state';
44
import { CarouselService } from '../carousel.service';
55
import { 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
})
1116
export 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

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.