0

Hello I am trying ng_focus on click button like

Input Box Code:

 <input type="text" placeholder="" class="promocode"    ng-focus="focus"  ng-model="text"  value="" /> 

Button Code:

<span ng-click="text = 'sheetesh'; focus=true"> Sheetesh </span>
<p>focus: {{focus}}</p>

And Its return true click on span but focus is not work.

focus: true

Screen Shot: its showing like that

1
  • ng-focus is not for setting focus. It's like ng-click. Value of ng-focus will be executed when focus event occurs. Commented Jan 8, 2016 at 7:11

2 Answers 2

3

document.getElementById

Try this:

<input id="myInput" type="text" placeholder="" class="promocode" ng-model="text" value="" />

<span ng-click="text = 'sheetesh'; document.getElementById('myInput').focus();"> Sheetesh </span>

angular.element

Alternative version with angular.element:

<span ng-click="text = 'sheetesh'; angular.element('#myInput').focus();"> Sheetesh </span>
Sign up to request clarification or add additional context in comments.

3 Comments

I have already use it but its not working. <input type="text" class="promocode" id ="promocodea" ng-model="text" value="" /> <span ng-click="text = 'sheetesh'; angular.element('#promocodea').focus();" class="fcs32">sheetesh</span>
@RITU are there any errors in console? Did you try the first solution?
yeah i tried Not showing any error in console but not working .
0

you not need to set focus. just add 'tabindex' attribute to element then automatically focus will go on element on

<input id="myInput" type="text" placeholder="" class="promocode" ng-model="text" value="" />

<span ng-click="text = 'sheetesh';" tabindex="0"> Sheetesh </span>

onclick

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.