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

Popular posts from this blog

sql - invalid in the select list because it is not contained in either an aggregate function -

Angularjs unit testing - ng-disabled not working when adding text to textarea -

How to start daemon on android by adb -