I'm tring to create a focus directive when i open a page with inside a form in the first input text filed.This is the directive
app.directive("getFocus", function() {
return {
restrict: 'AC',
link: function(scope, element){
console.log("focus!");
element.focus();
}
}
});
and in my html input
<input id="ss" data-ng-model="item.value" type="text" data-ng-class="{'get-focus': $first}">
<input id="tt" type="text" data-ng-model="item.value" data-ng-class="{'get-focus': $first}">
i use ng-class because is a dynamic form creating cycling a json and i don't know which input is created for first. The directive seems not working. Infact, the console.log not appears in the console.. Something's wrong?
ng-class. they can be used only with the html class attribute.getFocusdirective will be added based on a condition. We need to re-compile the node after the class is added to get it work