在制作新幻灯片后设置活动幻灯片

在制作新幻灯片后设置活动幻灯片

本文介绍了Angular UI Boostrap Carousel 在制作新幻灯片后设置活动幻灯片的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个简单的轮播示例.Plnkr 上的示例显示了我在应用程序中的操作.我必须更改应用程序中的幻灯片.当我在更改幻灯片后设置活动幻灯片时,它会转到该幻灯片,然后滑出被遗忘或转到第一张幻灯片.我怎么解决这个问题?以便在制作新幻灯片后我可以转到正确的幻灯片?

I have a simple Carousel example. The example on Plnkr shows what I do in my application. I have to change the slides in my application. When I set the active slide after I change slides it goes to that slide and then slides out into oblivion or it goes to the first slide. How can I solve this problem? So that after making new slides I can go to the right slide?

http://plnkr.co/edit/PJg9U4HZ1k5aSTSvbl3k?p=preview

angular.module('plunker', ['ui.bootstrap', 'ngTouch']);
    function CarouselDemoCtrl($scope) {
        $scope.genderPerson = "men";
        $scope.myInterval = -1;
        $scope.slides = [];

        $scope.$watch("genderPerson", function( newValue, oldValue ) {
            $scope.MakeSlides();
        });

        $scope.MakeSlides = function() {
            var newSlides = [];
            for ( var i = 0; i < 10; i++ ) {
                newSlides[i] = { image: 'http://api.randomuser.me/portraits/' + $scope.genderPerson + '/' + i + '.jpg' };
             }
             $scope.slides = newSlides;
             if ( $scope.slides[6] ) {
                 $scope.slides[6].active=true;
             }
        }
    }

推荐答案

看起来存在竞争条件,如果我将活动幻灯片设置为延迟超时,它似乎可以工作:

Looks like there is a race condition, if I wrap the active slide set in a timeout with a delay it seems to work:

  $timeout(function () {
    $scope.slides[6].active=true;
  }, 100);

这篇关于Angular UI Boostrap Carousel 在制作新幻灯片后设置活动幻灯片的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-06 13:41