티스토리 뷰

엣지 케이스, 즉 인덱스 크기가 0 또는 4에 도달하는 경우에 대해 묻는 경우 다음과 같이 코드를 수정할 수 있습니다.

(또한, 당신은에서 그 함수를 등록해야합니다 $scope)

$scope.switchImage = function(step) {
  self.index += step;
  
    // When user keeps clicking next image and index crosses end of array
      if (self.index == self.images.length) {
           // reset to zero
                self.index = 0;
                  } else if (self.index < 0) {
                       // else if user keeps clicking previous image and index goes negative
                            // reset to the last image
                                 self.index = self.images.length - 1;
                                   }
                                   
                                     $scope.image = self.images[self.index];
                                     };
                                     


출처
https://stackoverflow.com/questions/39940135
댓글
공지사항
Total
Today
Yesterday
«   2025/08   »
1 2
3 4 5 6 7 8 9
10 11 12 13 14 15 16
17 18 19 20 21 22 23
24 25 26 27 28 29 30
31