Angular无法获得渲染段落的高度

时间:2016-08-18 07:08:49

标签: javascript angularjs

我正在尝试根据段落中没有行来显示更多/更少的指令。我无法得到段落所呈现的确切高度。

如何获得?

app.directive('moreLess', function(){
    return{
        restrict: 'AE',
        scope: {
            mlText: '@'
        },
        template:"<span>{{mlText}}</span>",
        compile: function(elem, attributes){

            return {
                post: function(scope, elem, attributes, controller, transcludeFn){
                    var lineHeight = elem.css('lineHeight');
                    //var lines = elem[0].height;
                    console.log(elem[0].offsetHeight);
                    console.log(elem[0].scrollHeight );
                    console.log(elem[0].parentNode.scrollHeight );
                    console.log(elem.css('height'));
                }
            }
        },
        controller: function($scope){

        }
    }
})

0 个答案:

没有答案