uiuniversal / ngu-carousel

Angular Universal carousel
https://ngu-carousel.netlify.app
MIT License
326 stars 105 forks source link

Next arrow button does not work when carousel items are 2 #464

Closed azuxx closed 11 months ago

azuxx commented 12 months ago

Describe the bug "Next item arrow" button does not work when carousel items are 2. Otherwise it works properly. Please find the code below as my current implementation I did following your documentation. Do you find in there any code issues would prevent carousel to work properly? Or, am I missing something else needed to let it properly work?

<ngu-carousel #galleryCarousel
                          [inputs]="carouselTileConfig"
                          [dataSource]="activityItem?._famoloId ? activityItem.caseStudyGallery : activityItem.gallery">
              <ngu-tile *nguCarouselDef="let item; let i = index">
                <div class="card-gallery-image" [style.background]="'url(' + item.url + ')'">
                  <div>
                    <button (click)="$event.stopPropagation();onToggleCollectionClick(activityItem)"
                            mat-icon-button color="primary"
                            aria-label="toggle collection">
                      <mat-icon
                        [svgIcon]="activityItem?._existingItineraryId ? 'heart-filled' : 'heart-empty'"></mat-icon>
                    </button>
                    <ng-template [ngTemplateOutlet]="cardFlipButtonTpl"
                                 [ngTemplateOutletContext]="{activityItem}"></ng-template>
                  </div>
                  <button class="card-gallery-left" mat-mini-fab NguCarouselPrev
                          (click)="$event.stopPropagation();manuallyMoveCardItem(galleryCarousel, -1);"
                          [style.opacity]="galleryCarousel.isFirst ? 0.5 : 0.9">
                    <mat-icon svgIcon="left-arrow"></mat-icon>
                  </button>
                  <button class="card-gallery-right" mat-mini-fab NguCarouselNext
                          color="accent"
                          (click)="$event.stopPropagation();manuallyMoveCardItem(galleryCarousel,1);"
                          [style.opacity]="galleryCarousel.isLast ? 0.5 : 0.9">
                    <mat-icon svgIcon="right-arrow"></mat-icon>
                  </button>
                  <ul class="card-gallery-points" NguCarouselPoint>
                    <li *ngFor="let pointItem of galleryCarousel.pointNumbers; let j = index"
                        [class.active]="pointItem==galleryCarousel.activePoint"
                        (click)="$event.stopPropagation();galleryCarousel.moveTo(j)"></li>
                  </ul>
                </div>
              </ngu-tile>
            </ngu-carousel>
  manuallyMoveCardItem(galleryCarousel: NguCarousel<any>, value: number) {
    if (value === -1) {
      let newPoint = galleryCarousel.activePoint - 1;
      if (newPoint < 0) {
        newPoint = 0;
      }
      galleryCarousel.moveTo(newPoint);
    } else if (value === 1) {
      let newPoint = galleryCarousel.activePoint + 1;
      if (newPoint >= galleryCarousel.pointNumbers.length) {
        newPoint = galleryCarousel.pointNumbers.length - 1;
      }
      galleryCarousel.moveTo(newPoint);
    }
  }

Expected behavior You should move to the next carousel item even though there are only two items.

Desktop (please complete the following information):

Additional context Version of Angular: 15 carousel: @ngu/carousel": "^7.1.3"

Looking forward to hearing any helpful suggestions from anyone, thanks heaps

marikadeveloper commented 11 months ago

Same issue here, waiting for updates

santoshyadavdev commented 11 months ago

Can you refer the example and check https://deploy-preview-468--ngu-carousel.netlify.app/tile-2-images

azuxx commented 11 months ago

Can you refer the example and check https://deploy-preview-468--ngu-carousel.netlify.app/tile-2-images

thank you @santoshyadavdev ! Your example guided me properly to solution, it's working!