2016-06-28 6 views
0

템플릿은 탭이 2 개인 탭입니다. 첫 번째 탭에는 input 필드에 초점을두고 싶습니다. 앱이 input 필드에 포커스가있는 상태에서 시작될 때 작동하지만 두 번째 탭으로 전환 한 다음 첫 번째 탭으로 돌아 가면 입력에 포커스가 손실됩니다.입력 필드에 초점 맞추기

탭 2에서 1로 넘어갈 때 초점을 맞추고 싶습니다. 요소 바깥을 클릭하면 포커스도 잃게됩니다. 실제로 input 필드가 항상 집중되기를 원합니다.

.directive('focusMe', function($timeout) { 
    return { 
    scope: { trigger: '=focusMe' }, 
    link: function(scope, element) { 
     scope.$watch('trigger', function(value) { 
     if(value === true) { 
      //console.log('trigger',value); 
      //$timeout(function() { 
      element[0].focus(); 
      scope.trigger = true; 
      //}); 
     } 
     }); 
    } 
    }; 
}); 


<label class="item item-input" focus-me> 
    <input type="number" class="somett" ng-model="code" ng-model-options="{ debounce: 100 }" placeholder="Ready" ng-change="load(code) " focus-on="focusTextInput" autofocus> 
</label> 

답변

1

당신은 View LifeCycle and Events를 사용할 수 있습니다

나는 몇 이미 언급 한 솔루션을 시도했다.

컨트롤러에 추가하십시오.

$scope.$on('$ionicView.enter', function() { 
    $scope.$broadcast("focusTextInput"); 
}); 
+0

감사합니다. – Mark