+ Start a Discussion
Salesforce####Salesforce#### 

Aura :handler in lightning ,

hello Team ,
can yhou please tell me when do we use Aura :handler in lightning , what is the purpose , in what cirucmstanses we use it ??
{!Piyush_soni__c}{!Piyush_soni__c}
hi Salesforce####
in lightning component <aura:handler... > is used for handle standard and custom events
we can create our custom lightning event and also use standard events, standard lightning event is automatically fired when related event is fire
standard event like -:
1. aura:valueInit - :  Indicates that an app or component has been initialized.
This event is automatically fired when an app or component is initialized, prior to rendering. The aura:valueInit event is handled by a client-side controller. A component can have only one <aura:handler name="init"> tag to handle this event.
<aura:handler name="init" value="{!this}" action="{!c.doInit}"/>
2.aura:waiting -:  Indicates that the app or component is waiting for a response to a server request. This event is fired before aura:doneWaiting.
This event is automatically fired when a server-side action is added using $A.enqueueAction() and subsequently run, or when it’s expecting a response from an Apex controller. The aura:waiting event is handled by a client-side controller. A component can have only one <aura:handler event="aura:waiting"> tag to handle this event.
<aura:handler event="aura:waiting" action="{!c.showSpinner}"/>
3. aura:doneWaiting - :  Indicates that the app or component is done waiting for a response to a server request. This event is preceded by an aura:waiting event. This event is fired after aura:waiting.
This event is automatically fired if no more response from the server is expected. The aura:doneWaiting event is handled by a client-side controller. A component can have only one <aura:handler event="aura:doneWaiting"> tag to handle this event.
 
<aura:handler event="aura:doneWaiting" action="{!c.hideSpinner}"/>
and many more ...you can see all standard events in your org
https://<myDomain>.lightning.force.com/auradocs/reference.app

User-added image

i hope it helps you mark it best answer if it helps you so it make proepr solution for others.
or if you have any doubt you can ask here
thanks






 
Ajay K DubediAjay K Dubedi
Hi,
Every aura:handler has attributes it needs to work: name and value (for component events), or event (for application events), and action. Name is a predefined name for system events like init or change. This tells aura:handler which event to attach to. Event specifies an event to attach, which might actually be a custom event. Value specifies what the event is attached to: for an init, it will be the current component ("{!this}"); for other types of events, you might bind to an attribute value. Action, of course, is the method to actually execute to handle the event.
for eg:-
<aura:component controller="ContactListController">
     <aura:attribute name="contacts" type="Contact[]"/>
     <aura:handler name="init" value="{!this}" action="{!c.doInit}" />
     <ul>
         <aura:iteration items="{!v.contacts}" var="contact">
             <li>
                 <a href="{! '#/sObject/' + contact.Id + '/view'}">
                     <p>{!contact.Name}</p>
                     <p>{!contact.Phone}</p>
                 </a>
             </li>
         </aura:iteration>
     </ul>
 </aura:component>

Implement the Controller as follows:
({
     doInit : function(component, event) {
         var action = component.get("c.findAll");
         action.setCallback(this, function(a) {
             component.set("v.contacts", a.getReturnValue());
         });
         $A.enqueueAction(action);
     }
 })

 ### Code Highlights:
The controller assigned to the component (first line of code) refers to the server-side controller (ContactListController) you created in module 2.
The contacts attribute is defined to hold the list of Contact objects returned from the server.
The init handler is defined to execute some code when the component is initialized. That code (doInit) is defined in the component’s client-side controller (you’ll implement the controller in the next step).
<aura:iteration> is used to iterate through the list of contacts and create an <li> for each contact

I hope you find the above solution helpful. If it does, please mark as Best Answer to help others too.
Thanks,
Ajay Dubedi
sachinarorasfsachinarorasf
Hi Salesforce####,

I have gone through your problem.

You can use the below links:
1.https://developer.salesforce.com/docs/atlas.en-us.lightning.meta/lightning/events_component_handling_intro.htm
2.https://www.forcetalks.com/salesforce-topic/when-we-should-use-aura-handler-in-salesforce-lightning-component/

I hope you find the above solution helpful. If it does, please mark as Best Answer to help others too.

Thanks and Regards,
Sachin Arora