Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/457.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angularjs/21.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript angularjs x可编辑控件在完成或取消后失去焦点_Javascript_Angularjs_X Editable_Onsubmit_Onblur - Fatal编程技术网

Javascript angularjs x可编辑控件在完成或取消后失去焦点

Javascript angularjs x可编辑控件在完成或取消后失去焦点,javascript,angularjs,x-editable,onsubmit,onblur,Javascript,Angularjs,X Editable,Onsubmit,Onblur,我有基本的x-可编辑控件,如输入字段或选择。我只希望在完成控制后保持焦点 模板: <div ng-controller="Ctrl"> <a href="#" editable-text="user.name" e-onblur="console.log(this);">{{ user.name || 'empty' }}</a> </div> 请查看问题的实时版本: http://plnkr.co/edit/BjWwXIl

我有基本的x-可编辑控件,如输入字段或选择。我只希望在完成控制后保持焦点

模板:

 <div ng-controller="Ctrl">
      <a href="#" editable-text="user.name" e-onblur="console.log(this);">{{ user.name || 'empty' }}</a>
    </div>
请查看问题的实时版本:
http://plnkr.co/edit/BjWwXIlYyyLvRnVwO8m8?p=preview


我添加了一个模糊函数,但我似乎无法正确地修改它。如果还有其他解决方案,我想知道。

@heyNow,解决方案的概要如下:

  • 创建非隔离“焦点”指令并将其应用于链接元素。这应该采用布尔值,其中true设置焦点
  • 创建一个onhide函数,使“focus”指令中的条件为真
  • 创建一个“unset focus”函数,该函数将“focus”条件设置为false,并应使用ng blur和onshow调用该函数
  • 这是html

     <a href="#" onhide="onhide(user)" onshow="unsetFocus()" 
            ng-blur="unsetFocus()" focus="focusObj==user" 
            editable-text="user.name">
            {{ user.name || 'empty' }}
     </a>
    

    退房

    你能澄清一下吗?你所说的“控制完成后”是什么意思?使用完控件后,您想做什么?当我按
    enter
    时,它应该会完成编辑,但不会聚焦到页面上的第一件事情,它应该留在控件上,这样我就可以再次按
    enter
    (如果我愿意)并重新编辑它了!这管用!我将指令重命名为
    myFocus
    ,并将其作为属性添加到
    中,因为我不希望它干扰任何其他不可编辑的控件。这似乎也行得通。希望他们将此添加到库中,这样我们就不必想出这些解决方法
     <a href="#" onhide="onhide(user)" onshow="unsetFocus()" 
            ng-blur="unsetFocus()" focus="focusObj==user" 
            editable-text="user.name">
            {{ user.name || 'empty' }}
     </a>
    
    app.directive('focus', function($timeout) {
      return {
        scope: false,
        link: function(scope, element, attrs) {
          scope.$watch(attrs.focus, function(newval,oldval) {
            if (newval) { 
              $timeout(function() {
                element[0].focus(); 
              });
            }
          });
        }
      };
    });
    
    app.controller('Ctrl', function($scope, $filter) {
      $scope.user = {
        name: 'awesome user',
        status: 2
      };
      $scope.onhide = function(obj) {
        $scope.focusObj = obj;
      }
      $scope.unsetFocus = function() {
        $scope.focusObj = null;
      }
    }