在Angular中,如何从指令中获取元素的宽度?

时间:2014-10-31 23:28:47

标签: javascript angularjs

如何从此指令中获得el的宽度?

angular.module('carouselApp')
    .directive('waProgress', ['Pages', 'Carousel', '$window', '$timeout', function(Pages, Carousel, $window, $timeout) {
            return {
                scope: {
                    pages: "="
                },
                templateUrl: 'views/wa.progress.html',
                transclude: true,
                require: '^waCarousel',
                link: function(scope, el, attrs, ctrl) {
                    // console.log();
                    scope.progressed = false;
                    scope.$root.subscribe('updateCarousel', function(params){
                        // console.log('asdfasdf', params);
                        scope.progress = params;

                        scope.passedProgress = function(idx){
                          if(scope.progress.currentPage > idx){
                            console.log(el.width());
                            return  scope.progressed = true;
                            // scope.animatedWidth = $                                    
                            }  
                        }  
                    });
                    scope.futureProgress = function(idx) {
                        console.log(idx)
                    };
                }
            }
    }]);

1 个答案:

答案 0 :(得分:2)