javascript - Angular next 和 prev 导航数学逻辑

标签 javascript angularjs

对于数学大师们来说,这可能是小菜一碟。 prevSlide 返回正常 3-2-1-3-2... 等等。无论入口点如何。但是 nexSlide 从 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.nextSlide = function () {
    $scope.currentIndex = ($scope.currentIndex < $scope.slides.length -1) ? ++$scope.currentIndex : 0;
};

您只需将此行末尾的 1 更改为 0。您现在拥有的索引 1 实际上是第二张幻灯片。

Slide #: 1 -- 2 -- 3
Index #: 0 -- 1 -- 2

关于javascript - Angular next 和 prev 导航数学逻辑,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40473642/

相关文章:

javascript - 如何使用 Browserify 导出对象?

javascript - 预检请求中的跨域 cookie

angular - 错误 TS2724 : '"@angular/core "' has no exported member named ' NgModuleFactoryLoader'. 您的意思是 'NgModuleFactory' 吗?

javascript - Angular js 选项卡应用程序

javascript - 从客户端的 FileUpload 控件获取所有文件名

javascript - 在逻辑 block 之前引入新的 If 语句时如何构建代码

javascript - 函数 concat 和 push 显示出意外的行为

angularjs - Angular-JS strict-DI 不喜欢从 $routeProvider 注入(inject)解析的结果

javascript - Angular.js ng-repeat 验证条件中的多个输入

javascript - 我如何限制 angularjs 中的 $http 请求?