且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

角UI自举旋转木马制作幻灯片的新设置后,活动幻灯片

更新时间:2022-10-19 12:33:32

看起来像有一个竞争条件,如果我换行活动的幻灯片在超时设定似乎工作延迟:

  $超时(函数(){
    $ scope.slides [6]。主动= TRUE;
  },100);

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);