카테고리 없음
[자바 스크립트] Angular를 사용하여 버튼 클릭으로 이미지를 순환하는 방법은 무엇입니까?
필살기쓰세요
2021. 2. 19. 16:10
엣지 케이스, 즉 인덱스 크기가 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