Skip to content
This repository has been archived by the owner on Aug 6, 2022. It is now read-only.

Commit

Permalink
Fixed slides references and class initialization, fixes #227
Browse files Browse the repository at this point in the history
  • Loading branch information
sconix committed Jul 17, 2019
1 parent 7e39221 commit a83be0c
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions src/lib/swiper.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,9 @@ export class SwiperComponent implements AfterViewInit, OnDestroy {

@Output() indexChange = new EventEmitter<number>();

@ViewChild('swiperSlides', { static: true }) swiperSlides?: ElementRef;
@ViewChild('swiperSlides', { static: false }) swiperSlides?: ElementRef;

@ViewChild(SwiperDirective, { static: true }) directiveRef?: SwiperDirective;
@ViewChild(SwiperDirective, { static: false }) directiveRef?: SwiperDirective;

get isAtLast(): boolean {
return (!this.directiveRef || !this.directiveRef.swiper()) ?
Expand Down Expand Up @@ -168,10 +168,10 @@ export class SwiperComponent implements AfterViewInit, OnDestroy {

this.swiperConfig.assign(this.config); // Custom configuration

if (this.swiperConfig.pagination === true ||
if (this.swiperSlides && (this.swiperConfig.pagination === true ||
(this.swiperConfig.pagination && typeof this.swiperConfig.pagination === 'object' &&
(!this.swiperConfig.pagination.type || this.swiperConfig.pagination.type === 'bullets') &&
!this.swiperConfig.pagination.renderBullet && this.swiperConfig.pagination.el === '.swiper-pagination'))
!this.swiperConfig.pagination.renderBullet && this.swiperConfig.pagination.el === '.swiper-pagination')))
{
this.config = this.config || {};

Expand All @@ -182,7 +182,9 @@ export class SwiperComponent implements AfterViewInit, OnDestroy {
el: '.swiper-pagination',

renderBullet: (index: number, className: string) => {
const children = this.swiperSlides ? this.swiperSlides.nativeElement.children : [];
let children = this.swiperSlides ? Array.from(this.swiperSlides.nativeElement.children) : [];

children = children.filter((child: any) => child.classList.contains('swiper-slide'));

let bullet = `<span class="${className} ${className}-middle" index="${index}"></span>`;

Expand Down Expand Up @@ -214,7 +216,7 @@ export class SwiperComponent implements AfterViewInit, OnDestroy {
const children = this.swiperSlides.nativeElement.children;

for (let i = 0; i < children.length; i++) {
if (!children[i].classList.contains('swiper-slide')) {
if (/swiper-.*/.test(children[i].className) === false) {
updateNeeded = true;

children[i].classList.add('swiper-slide');
Expand Down

0 comments on commit a83be0c

Please sign in to comment.