1

Suppose I have the following setup:

<form>
    <input type="text" id="text1">
    <input type="text" id="text2">
</form>

In AngularJS, is there any way for me to determine when, say, the user deselects #text1, for example by clicking #text2, or clicking somewhere else on the screen? I am aware the ng-change lets me listen to changes in the value of #text1 itself, but I see no way to determine when the user actually leaves the field.

1 Answer 1

3

You can use ngBlur for this

https://docs.angularjs.org/api/ng/directive/ngBlur

<form>
  <input type="text" id="text1" ng-blur="iHaveLostFocusDoSomethingWithIt()">
  <input type="text" id="text2">
</form>
Sign up to request clarification or add additional context in comments.

2 Comments

Keep in mind that ng-blur is available only since Angular 1.2
Correct, i keep forgetting that some people use old version for no reason at all ;)

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.