Hello,

I am unable to create a custom directive that puts the focus on an input 
element the directive is on...
This is what I have:
a view with 3 input elements, when the view is displayed I want the first 
input element to receive focus. I try to do that using a custom directive:

<div class="span2"><input type="text" ng-model="newContact.firstName" 
placeholder="First" ng-bind="focus"></div>
<div class="span2"><input type="text" ng-model="newContact.lastName" 
placeholder="Last"></div>
<div class="span2"><input type="text" ng-model="newContact.address" 
placeholder="Address"></div>

var directives = angular.module("iShareApp.directives",[]);

directives.directive("focus",
    function(){
        return {
            link: function(scope,element,attrs){
                element[0].focus(); //element.focus(); gives the same result
            }
        };
});

The input elements for First,Last and Address are shown, with the 
placeholders and all but I see no cursor in the first input. Am I doing 
something wrong?

Marc

-- 
You received this message because you are subscribed to the Google Groups 
"AngularJS" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/angular.
For more options, visit https://groups.google.com/groups/opt_out.

Reply via email to