Skip to content

Commit ce2b853

Browse files
committed
refactor(carousel): carousel.config migrate to inject()
1 parent d16cae1 commit ce2b853

File tree

3 files changed

+12
-10
lines changed

3 files changed

+12
-10
lines changed

projects/coreui-angular/src/lib/carousel/carousel.config.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,5 @@ export class CarouselConfig {
99
/* Default direction of auto changing of slides */
1010
direction: 'next' | 'prev' = 'next';
1111
/* Default interval of auto changing of slides */
12-
interval = 0;
12+
interval?: number;
1313
}

projects/coreui-angular/src/lib/carousel/carousel/carousel.component.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ describe('CarouselComponent', () => {
4141
expect(component.activeIndex()).toBe(0);
4242
expect(component.animate()).toBe(true);
4343
expect(component.direction()).toBe('next');
44-
expect(component.interval()).toBe(0);
44+
expect(component.interval()).toBe(-1);
4545
});
4646

4747
it('should call timer functions', fakeAsync(() => {

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

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@ import {
44
DestroyRef,
55
effect,
66
ElementRef,
7-
Inject,
87
inject,
98
input,
109
linkedSignal,
10+
numberAttribute,
1111
OnDestroy,
1212
OnInit,
1313
output
@@ -37,28 +37,30 @@ import { CarouselConfig } from '../carousel.config';
3737
}
3838
})
3939
export class CarouselComponent implements OnInit, OnDestroy, AfterContentInit {
40+
private config = inject<CarouselConfig>(CarouselConfig);
41+
4042
readonly #hostElement = inject(ElementRef);
4143
readonly #carouselService = inject(CarouselService);
4244
readonly #carouselState = inject(CarouselState);
4345
readonly #intersectionService = inject(IntersectionService);
4446
readonly #listenersService = inject(ListenersService);
4547

46-
constructor(@Inject(CarouselConfig) private config: CarouselConfig) {
48+
constructor() {
4749
this.loadConfig();
4850
}
4951

5052
loadConfig() {
51-
this.activeIndex.set(this.config?.activeIndex ?? this.activeIndex());
52-
this.animate.set(this.config?.animate ?? this.animate());
53-
this.direction.set(this.config?.direction ?? this.direction());
54-
this.interval.set(this.config?.interval ?? this.interval());
53+
this.activeIndex.update((activeIndex) => this.config?.activeIndex ?? activeIndex);
54+
this.animate.update((animate) => this.config?.animate ?? animate);
55+
this.direction.update((direction) => this.config?.direction ?? direction);
56+
this.interval.update((interval) => this.config?.interval ?? interval);
5557
}
5658

5759
/**
5860
* Index of the active item.
5961
* @return number
6062
*/
61-
readonly activeIndexInput = input<number>(0, { alias: 'activeIndex' });
63+
readonly activeIndexInput = input(0, { alias: 'activeIndex', transform: numberAttribute });
6264

6365
readonly activeIndex = linkedSignal({
6466
source: this.activeIndexInput,
@@ -92,7 +94,7 @@ export class CarouselComponent implements OnInit, OnDestroy, AfterContentInit {
9294
* @return number
9395
* @default 0
9496
*/
95-
readonly intervalInput = input<number>(0, { alias: 'interval' });
97+
readonly intervalInput = input(-1, { alias: 'interval', transform: numberAttribute });
9698

9799
readonly interval = linkedSignal({
98100
source: this.intervalInput,

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy