简体   繁体   English

在angularJS中调整textarea的大小(在uib-tab内部)

[英]Resizing textarea in angularJS (inside uib-tab)

Hi I m using https://hassantariqblog.wordpress.com/2016/07/27/angularjs-textarea-auto-resize-directive/ in AngularJS to resize text area based on input. 嗨,我在AngularJS中使用https://hassantariqblog.wordpress.com/2016/27/angularjs-textarea-auto-resize-directive/来根据输入来调整文本区域的大小。 And I am using template like below(description.tpl.html): 我正在使用如下模板(description.tpl.html):

 <textarea class="form-control" auto-resize placeholder="Please enter description here..." style="resize: none;min-height:100px;" ng-model="description" autofocus></textarea>  

And I display the text area in 2 places. 然后在2个地方显示文本区域。 However, the size of textarea is not updated when I use it inside a tab like below. 但是,当我在如下所示的选项卡中使用textarea时,不会更新它的大小。 However, when I start typing in the textarea,it updates the size. 但是,当我开始输入文本区域时,它会更新大小。

 <uib-tab heading= DESCRIPTION >                      
     <div ng-include="'description.tpl.html'"></div>
 </uib-tab>

So I tried to add this code, when the tab is selected, how can I call the directive? 因此,我尝试添加此代码,当选择选项卡时,如何调用该指令?

element.css({ 'height': 'auto', 'overflow-y': 'hidden' });
element.css('height', element[0].scrollHeight + 'px');

Thanks in advance! 提前致谢!

I added a boolean scope variable and set it to true when the tab is selected. 我添加了一个布尔作用域变量,并在选择选项卡时将其设置为true。 Added the following code to the directive: 在指令中添加了以下代码:

     scope.$watch('descriptionTabSelected', function(descriptionTabSelected){
                    if(descriptionTabSelected){
                        element.css({ 'height': 'auto', 'overflow-y': 'hidden' });
                        $timeout(function () {
                            element.css('height', element[0].scrollHeight + 'px');
                        }, 100);
                    }
                });

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM