javascript - Focus on input field -
template 'tabs' 2 tabs. on first tab, have input
field want put focus on. working when app starts input
field being focused, when switch second tab , first tab, input loses focus.
i focused when go tab 2 1 too. when click outside element, loses focus well. want input
field focused.
i tried 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 , events.
add controller.
$scope.$on('$ionicview.enter', function() { $scope.$broadcast("focustextinput"); });
Comments
Post a Comment