Angular 自定义指令 repeatFinish 向控制器传递消息

 
app.directive('repeatFinish',function () {
    return {
        link:function (scope) {
            if(scope.$last == true){
                setTimeout(function () {
                    //向父控制器传递事件消息
                    scope.$emit('repeatFinishCallback');
                },100)
            }
        }
    }
})
 $scope.$on('repeatFinishCallback',function(){
        //repeat后需要进行的操作
        mySwiper = new Swiper('.swiper-container', {
            scrollbar: {
                el: '.swiper-scrollbar',
                dragSize: '6px'
            },
            on:{
                slideChange:function () {
                    //切换tab
                    var index = this.activeIndex;
                    // $scope.$apply(function () {
                    //     $scope.toIndex = index;
                    // })
                    $scope.$applyAsync(function () {
                        $scope.toIndex = index;
                    });
                }
            }
        });


    });

 

你可能感兴趣的:(JavaScript)