How do you Bind to Angular-UI's Carousel Slide Events?

后端 未结 6 1685
一整个雨季
一整个雨季 2020-12-02 21:24

I\'m using Angular-UI\'s carousel and I need to tell my google charts to redraw after they have slid into view. In spite of what I\'ve read, I can\'t seem to hook into the e

6条回答
  •  余生分开走
    2020-12-02 22:15

    I managed to modify runTarm's answer so that it calls the callback once the slide has finished sliding into view (i.e. the sliding animation has finished). Here's my code:

    .directive('onCarouselChange', function ($animate, $parse) {
        return {
            require: 'carousel',
            link: function (scope, element, attrs, carouselCtrl) {
                var fn = $parse(attrs.onCarouselChange);
                var origSelect = carouselCtrl.select;
                carouselCtrl.select = function (nextSlide, direction) {
                    if (nextSlide !== this.currentSlide) {
                        $animate.on('addClass', nextSlide.$element, function (elem, phase) {
                            if (phase === 'close') {
                                fn(scope, {
                                    nextSlide: nextSlide,
                                    direction: direction,
                                });
                                $animate.off('addClass', elem);
                            }
                        });
                    }
                    return origSelect.apply(this, arguments);
                };
            }
        };
    });
    

    The secret lies in using $animate's event handler to call our function once the animation is finished.

提交回复
热议问题