Skip to content

Commit 5d4ffdc

Browse files
authored
feat(angular): support [ngClass] in swiperSlide (#5562)
1 parent 5465b6c commit 5d4ffdc

File tree

3 files changed

+7
-1
lines changed

3 files changed

+7
-1
lines changed

playground/angular/src/app/home/home.component.html

+2-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22
<h6>Initial value true</h6>
33
<button (click)="p1 = !p1">{{ p1 ? 'hide' : 'show' }}</button>
44
<swiper [pagination]="p1" class="mySwiper">
5-
<ng-template swiperSlide>Slide 1</ng-template><ng-template swiperSlide>Slide 2</ng-template
5+
<ng-template swiperSlide class="testClass1">Slide 1</ng-template
6+
><ng-template swiperSlide [ngClass]="example">Slide 2</ng-template
67
><ng-template swiperSlide>Slide 3</ng-template><ng-template swiperSlide>Slide 4</ng-template
78
><ng-template swiperSlide>Slide 5</ng-template><ng-template swiperSlide>Slide 6</ng-template
89
><ng-template swiperSlide>Slide 7</ng-template><ng-template swiperSlide>Slide 8</ng-template

playground/angular/src/app/home/home.component.ts

+1
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ SwiperCore.use([
3333
export class HomePage {
3434
p1 = true;
3535
p2 = false;
36+
example = 'testClass2';
3637
@ViewChild('swiperRef', { static: false }) swiperRef?: SwiperComponent;
3738

3839
show: boolean;

src/angular/src/swiper-slide.directive.ts

+4
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@ import { coerceBooleanProperty } from './utils/utils';
66
export class SwiperSlideDirective {
77
@Input() virtualIndex: number;
88
@Input() class: string = '';
9+
@Input()
10+
set ngClass(val: string) {
11+
this.class = [this.class || '', val].join(' ');
12+
}
913
@Input('data-swiper-autoplay') autoplayDelay: string | null = null;
1014
@Input()
1115
set zoom(val: boolean) {

0 commit comments

Comments
 (0)