Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to pass the input element as a parameter in ng-blur?

This is my input:

<input type="number" value="{{ bom.Id._Value }}" name="id" data-ng-model="bom.Id._Value" data-ng-blur="myClass.myFunc();" required>

If I pass this or angular.element(this) in the ng-blur I don't get the input element in the function. What I want is to receive the current input element in myFunc() as a parameter. What is the standard way for it?

like image 289
dude Avatar asked Aug 07 '15 10:08

dude


People also ask

How does ng blur work?

The ng-blur directive tells AngularJS what to do when an HTML element loses focus. The ng-blur directive from AngularJS will not override the element's original onblur event, both the ng-blur expression and the original onblur event will be executed.

What is the use of blur event in angular?

A blur event fires when an element has lost focus. Note: As the blur event is executed synchronously also during DOM manipulations (e.g. removing a focussed input), AngularJS executes the expression using scope. $evalAsync if the event is fired during an $apply to ensure a consistent state.

How do you blur in Javascript?

jQuery blur() Method The blur event occurs when an element loses focus. The blur() method triggers the blur event, or attaches a function to run when a blur event occurs. Tip: This method is often used together with the focus() method.

What is blur event in Javascript?

The blur event fires when an element has lost focus. The event does not bubble, but the related focusout event that follows does bubble. The opposite of blur is the focus event, which fires when the element has received focus. The blur event is not cancelable.


1 Answers

<input type="number" value="{{ bom.Id._Value }}" name="id" data-ng-model="bom.Id._Value" data-ng-blur="myClass.myFunc($event);" required>

In Controller:

myClass.myFunc = function(e){
  console.log(e.target);
};
like image 176
Aravinder Avatar answered Oct 02 '22 13:10

Aravinder