专注于输入领域(Focus on input field)

编程入门 行业动态 更新时间:2024-10-26 20:30:17
专注于输入领域(Focus on input field)

模板是带有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>

Template is 'tabs' with 2 tabs. On the first tab, I have an input field I want to put focus on. It is working when the app starts with the input field being focused, but when I switch to the second tab and then back to the first tab, the input loses focus.

I would like it be focused when I go from tab 2 to 1 too. When I click outside the element, it to loses focus as well. I actually want that input field to be ALWAYS focused.

I tried some already mentioned solutions:

.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"); });

You can use View LifeCycle and Events.

Add this to your controller.

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

更多推荐

本文发布于:2023-08-02 15:58:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1378722.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:领域   专注于   Focus   input   field

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!