【问题标题】:Angular: TextArea losing focus each times textarea model gets updateAngular:每次更新文本区域模型时,文本区域都会失去焦点
【发布时间】:2015-07-12 18:45:25
【问题描述】:

我正在使用Socket.io 在更新 textarea 上的数据时向所有订阅者广播更改,但我遇到的问题是,当数据更新并且textareafocus state 中时,它会丢失所有内容focus。我只想更新textarea,仅当它在blur state 中而不是在focus state 中。

我试过写这个,但它不起作用

<textarea ng-model-options="{ updateOn: 'blur'}"  ng-model="value.note"></textarea>

【问题讨论】:

    标签: javascript jquery angularjs socket.io


    【解决方案1】:

    找到替代解决方案

    <textarea ng-blur="saveNote(value)" ng-model="value.note" ></textarea>
    

    在控制器中

    app.controller('testController', function($scope){ 
        $scope.persistedValue = '';
        $scope.saveNote = function(value){
           var note = value.note;
           if(note !== $scope.persistedValue){
             //Only save if persistentValue is different from note value  
    
    
           }
        }
    });
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2011-05-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-02-06
      • 2012-10-28
      相关资源
      最近更新 更多