Skip to content

Commit fc991d1

Browse files
authored
perf(module:carousel): do not run change detection when the timer fires (#7136)
1 parent 7acb8db commit fc991d1

File tree

3 files changed

+8
-4
lines changed

3 files changed

+8
-4
lines changed

components/carousel/carousel.component.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ export class NzCarouselComponent implements AfterContentInit, AfterViewInit, OnD
172172
constructor(
173173
elementRef: ElementRef,
174174
public readonly nzConfigService: NzConfigService,
175-
private readonly ngZone: NgZone,
175+
public readonly ngZone: NgZone,
176176
private readonly renderer: Renderer2,
177177
private readonly cdr: ChangeDetectorRef,
178178
private readonly platform: Platform,

components/carousel/strategies/experimental/flip-strategy.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,11 @@ export class NzCarouselFlipStrategy extends NzCarouselBaseStrategy {
2828
this.renderer.setStyle(content.el, 'backface-visibility', 'hidden');
2929
});
3030

31-
timer(this.carouselComponent!.nzTransitionSpeed).subscribe(() => {
32-
this.contents.forEach(c => this.renderer.setStyle(c.el, 'transition', ['transform 500ms ease 0s']));
31+
const { carouselComponent } = this;
32+
carouselComponent!.ngZone.runOutsideAngular(() => {
33+
timer(carouselComponent!.nzTransitionSpeed).subscribe(() => {
34+
this.contents.forEach(c => this.renderer.setStyle(c.el, 'transition', ['transform 500ms ease 0s']));
35+
});
3336
});
3437
}
3538
}

components/carousel/typings.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
*/
55

66
import { Direction } from '@angular/cdk/bidi';
7-
import { InjectionToken, QueryList } from '@angular/core';
7+
import { InjectionToken, NgZone, QueryList } from '@angular/core';
88

99
import { NzCarouselContentDirective } from './carousel-content.directive';
1010
import { NzCarouselBaseStrategy } from './strategies/base-strategy';
@@ -21,6 +21,7 @@ export interface NzCarouselComponentAsSource {
2121
slickTrackEl: HTMLElement;
2222
activeIndex: number;
2323
dir: Direction;
24+
ngZone: NgZone;
2425
}
2526

2627
export interface NzCarouselStrategyRegistryItem {

0 commit comments

Comments
 (0)