用angularJs,HTML,slim自动扩展文本区域

时间:2018-08-23 20:33:00

标签: html angularjs slim

我正在尝试创建一个最大长度为500的自动扩展文本区域。这是我的html.slim代码部分:

 label
      | Add text
      span.t-medium-gray.fr.pt2
        | {{ textfield.value.length }}/500
 textarea id="TextArea" ng-model="textfield.value" maxlength="500" placeholder="Enter Text with your choice"

这是我尝试在controller.js文件中添加的内容:

    function loadData(bankId) {
                BankService.getData(bankId)
                  .then(function(res) {
                    $scope.bankId = res.data.id;
                    $scope.formData = res.data.form_data;
                    $timeout(expand, 0);
                    _.each($scope.formData, function(textfield) {
                      textfield.value = '';
                    });
                  })
              }    
    $scope.autoExpand = function(e) {
            var element = typeof e === 'object' ? e.target : document.getElementById(e);
            var scrollHeight = element.scrollHeight -60; // replace 60 by the sum of padding-top and padding-bottom
                    element.style.height =  scrollHeight + "px";
        };

function expand() {
           $scope.autoExpand('TextArea');
}

但是不幸的是,这段代码没有任何作用。甚至不显示UI中的文本字段。在哪里可以进行更改以使自动展开文本框正常工作?

0 个答案:

没有答案