angular.js - ionic combines angularjs with left and right clicks on the arrows to switch images. How to do this? I only know that ionic has an automatic carousel function.
高洛峰2017-05-15 17:10:14
0
2
767
Ionic combines angularjs with left and right clicks on the arrows to switch images. How to do this? I only know that ionic has an automatic carousel function
The image address is stored in the array, and the default image displays the 0th element of the array. Clicking the button will add or subtract 1 to the index of the current array element. Pay attention to boundary judgment and give corresponding prompts. OK.
The image address is stored in the array, and the default image displays the 0th element of the array. Clicking the button will add or subtract 1 to the index of the current array element. Pay attention to boundary judgment and give corresponding prompts. OK.
Code:
To use the arrow image switching function, just declare the imgList array you want to display in the controller and put the image url in it.
The default is to display the first one first, with index=0. $scope.curImg = imgList[0];
Click the right arrow index++, ng-click="toNext()" $scope.curImg = imgList[index]; Just set ng-src to the value of curImg in the displayed img tag.
Similarly click on the left arrow index--.
Also pay attention to the clickable control of the left and right arrows when index=0 and the index is the largest