angular指令系列---多行文本框自动高度

angular.module('MyApp')
    .directive('autoTextare', ['$timeout', function ($timeout) {
        return {
            restrict: 'A',
            require: '^?ngModel',
            link: function ($scope, iElm, iAttrs, controller) {
                var nowEle = angular.element(iElm[0]);
                $timeout(function () {
                    nowEle.css('height', 'auto');
                    nowEle.css('height', iElm[0].scrollHeight + 'px');
                }, 100)
                iElm.on('input', function (event) {
                    nowEle.css('height', 'auto');
                    nowEle.css('height', this.scrollHeight + 'px');
                })
            }
        }
    }])
    

 

posted @ 2016-06-23 19:37  何jason  阅读(795)  评论(0编辑  收藏  举报