I use ng-if to add/remove a typehead input for inline edition purpose. the ng-if value is updated by a "edit" button
So, what is the best or recommended way to give focus to the text input, once it's added to the dom ?
thanks
Lionel
I use ng-if to add/remove a typehead input for inline edition purpose. the ng-if value is updated by a "edit" button
So, what is the best or recommended way to give focus to the text input, once it's added to the dom ?
thanks
Lionel
The current version of AngularJS doesn't have a focus directive.
But you can refer Input autofocus attribute
And create you own directive for this usage.
Following Chen-Tsu Lin comment, here is a small directive for focusing element once they're added (used with ng-if)
module.directive('inputFocus',['$timeout', function($timeout){
'use strict';
return {
restrict: 'A',
link: function(scope, elem){
$timeout(function(){
elem[0].focus();
});
}
};
}]);
to use it:
<input type="text" input-focus ng-if="isShown" />
and here is the JsBin http://jsbin.com/texujona/5/