簡體   English   中英

專注於輸入領域

[英]Focus on input field

模板是帶有兩個標簽的“標簽”。 在第一個選項卡上,我有一個要重點關注的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>

您可以使用View LifeCycle和Events

將此添加到您的控制器。

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM