2015-12-13 50 views
3

我想调整textArea上焦点的行数,以消除模糊时的行数。除此之外,我想展示一个隐藏的div层。我目前的解决方案是通过Angularjs更新textarea行

<textarea class="form-control" rows="1" placeholder="Please enter text..." 
onfocus="this.rows=3" ng-focus="isVisible = !isVisible" onblur="this.rows=1" 
ng-blur="isVisible = !isVisible"></textarea> 

正如你可以从上面我必须使用两个属性,即HTML的onfocus以增加行和NG-重点更新ISVISIBLE看(以显示和隐藏DIV)。它的工作原理,但我想知道是否可以增加和减少使用ng-focus和ng-blur的行数。

div层,我的显示和隐藏

<div class="row" ng-show="isVisible" /> 

在此先感谢

回答

6

基本上,你可以使用ng-attr-rows设置rows动态属性值。你可以有像下面这样的东西。

基本上在每个摘要周期ng-attr-*指令评估它的表达式,在你的情况下*rows,并将该评估值添加到rows属性。

标记

<textarea ng-model="test" 
    ng-attr-rows="{{row || '1'}}" 
    ng-focus="row=3" 
    ng-blur="row=1"> 
</textarea> 

Demo Plunkr

+0

谢谢你对我的作品:) – Barry

+0

我在想,如果你能解释的表达{{行|| '1'}}。我以前没有见过这个 – Barry

+1

@你可以看看更新后的答案..我在那里粘贴了文档链接。 –