I'm trying to focus an input box with AngularJS. To achieve that I created a custom directive, but for some reasons it doesn't work on a particular input box.
This is my 'focus' directive:
angular.module('app.ui.input').directive('ooFocus', function()
{
return {
scope : {
trigger : '=ooFocus'
},
restrict : 'A',
link : function(scope, element, attrs)
{
scope.$watch('trigger', function(value)
{
if(value)
{
console.log('this will be printed');
element[0].focus();
element[0].select();
}
});
}
}
});
And this is how it looks like when it's being applied to the input box:
<input placeholder="Company name" type="text" ng-model="company.name" ng-blur="hide()" oo-focus="show" required>
The form containing the input box is hidden and it's displayed when show is set to true. show is passed to the oo-focus directive and I can see that the directive is printing this will be printed in the console whenever show is set to true, but for some reasons the input is not focused.