csvan
csvan

Reputation: 9474

AngularJS - input text element deselect event

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.

Upvotes: 1

Views: 2098

Answers (1)

maurycy
maurycy

Reputation: 8465

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>

Upvotes: 3

Related Questions