0

나는 HTML 요소에 포커스를 설정하는 AngularJs 지시문을 만들었습니다. 그러나 $ uibModal 요소에서 작동하지 않습니다

angular.module('ui.bootstrap.demo') 
    .directive('focus', ['$timeout', function ($timeout) { 
     return { 
      restrict: 'A', 
      link: function postLink(scope, element, attrs) { 
       scope.$watch(attrs.focus, function(value) { 
        if(value === true) { 
         $timeout(function() { 
          element[0].focus(); 
         }); 
        } 
       }); 
      } 
     }; 
    }]); 

http://plnkr.co/edit/BrnFt1kYZN7VsIFRCt3S?p=preview

가 어떻게이 $ uibModal 내부 요소에 초점을 설정할 수 있습니까?

답변

4

해결책을 찾았습니다 : 입력 요소에 자동 초점 속성을 추가하면 $ uibModal이 포커스를 설정합니다.

<div class="modal-body"> 
     <p class="input-group"> 
      <input type="text" class="form-control" autofocus/> 
     </p> 
    </div> 

http://plnkr.co/edit/yMNLLnSZL86ZYLsnuDV9?p=preview

+0

위대한 작품! 특히 대부분의 경우이 링크 기능에 액세스 할 수 없기 때문에 특히 그렇습니다. – Void