[英]Focus on input field
Template is 'tabs' with 2 tabs. 模板是带有两个标签的“标签”。 On the first tab, I have an
input
field I want to put focus on. 在第一个选项卡上,我有一个要重点关注的
input
字段。 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. 当应用程序以
input
字段为焦点开始时,它就可以正常工作,但是当我切换到第二个选项卡然后又回到第一个选项卡时,输入将失去焦点。
I would like it be focused when I go from tab 2 to 1 too. 当我也从选项卡2转到1时,我希望它能集中精力。 When I click outside the element, it to loses focus as well.
当我在元素外部单击时,它也会失去焦点。 I actually want that
input
field to be ALWAYS focused. 我实际上希望该
input
字段始终集中。
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>
You can use View LifeCycle and Events . 您可以使用View LifeCycle和Events 。
Add this to your controller. 将此添加到您的控制器。
$scope.$on('$ionicView.enter', function() {
$scope.$broadcast("focusTextInput");
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.