Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angularjs/21.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 角度下一个和上一个导航数学逻辑_Javascript_Angularjs - Fatal编程技术网

Javascript 角度下一个和上一个导航数学逻辑

Javascript 角度下一个和上一个导航数学逻辑,javascript,angularjs,Javascript,Angularjs,这对你们数学大师来说可能是小菜一碟。前一张幻灯片返回到精细的3-2-1-3-2。。。等等,不管进入点是什么。但是下一张幻灯片从1-2-3开始,然后是2-3-2-3…我肯定这是我的数学 $scope.currentIndex = 0; $scope.setCurrentSlideIndex = function (index) { $scope.currentIndex = index; }; $scope.isCurrentSlideIndex = function (index) {

这对你们数学大师来说可能是小菜一碟。前一张幻灯片返回到精细的3-2-1-3-2。。。等等,不管进入点是什么。但是下一张幻灯片从1-2-3开始,然后是2-3-2-3…我肯定这是我的数学

$scope.currentIndex = 0;
$scope.setCurrentSlideIndex = function (index) {
    $scope.currentIndex = index;
};
$scope.isCurrentSlideIndex = function (index) {
    return $scope.currentIndex === index;
};
$scope.prevSlide = function () {
    $scope.currentIndex = ($scope.currentIndex > 0) ? --$scope.currentIndex : $scope.slides.length - 1;
};
$scope.nextSlide = function () {
    $scope.currentIndex = ($scope.currentIndex < $scope.slides.length -1) ? ++$scope.currentIndex : 1;
};
$scope.currentIndex=0;
$scope.setCurrentSlideIndex=函数(索引){
$scope.currentIndex=索引;
};
$scope.isCurrentSlideIndex=函数(索引){
返回$scope.currentIndex==索引;
};
$scope.prevsiled=函数(){
$scope.currentIndex=($scope.currentIndex>0)?--$scope.currentIndex:$scope.slides.length-1;
};
$scope.nextSlide=函数(){
$scope.currentIndex=($scope.currentIndex<$scope.slides.length-1)?++$scope.currentIndex:1;
};

救命啊

您必须更改以匹配您的上下文,但是下面函数
previous()
next()
中的逻辑可能会有所帮助

var numSlides = 3;

function previous(current){
  current--;
  return current >= 0 ? current : numSlides;
}

function next(current){
  current++;
  return current <= numSlides ? current : 0;
}
var numSlides=3;
前一功能(当前){
当前--;
返回电流>=0?电流:numSlides;
}
功能下一步(当前){
电流++;

返回电流任何时钟算法都可以使用模(%)运算符。
return(++current)%numSlides
这是纯javascript的一个很好的解决方案,但另一个答案帮助我做得更好,因为它仍然是有角度的,并且不需要太多的工作。此外,我不能硬编码幻灯片的数量。如果用户向组件添加了3张以上的幻灯片,它必须保持动态。但是我做了+1您的答案。谢谢!Golden!谢谢lot!
$scope.nextSlide = function () {
    $scope.currentIndex = ($scope.currentIndex < $scope.slides.length -1) ? ++$scope.currentIndex : 0;
};
Slide #: 1 -- 2 -- 3
Index #: 0 -- 1 -- 2