+ Start a Discussion

What is the use of  <aura:handler name="init" value="{!this}" action="{!c.doInit}"/

What is the use of  <aura:handler name="init" value="{!this}" action="{!c.doInit}"/>
Raj VakatiRaj Vakati
Hi ,
You think it like a constructor for OOP. It will invoke on the component initialization phase.
Hi Vijaya,

This aura handler goes like this:

<Aura> --> lightning specific keyword same as  <apex> in salesforce classic. 
<aura:handler> --> is used to handle stanadard / custom events. 
name="init" --> this is defining the name of aura:handler
value={!this}  --> passing the current information to controller
action ={!c.doInit} --> calling the "doInit" of controller.

Hope this makes sense.

Hi vijayabhaskarareddy,

<aura:handler name="init" value="{!this}" action="{!c.doInit}"/>

This registers an init event handler for the component.

init is a predefined event sent to every component.

After the component is initialized, the doInit action is called in the component's controller.
In this sample, and the controller action sets an attribute value, but it could do something more interesting,
such as firing an event.Setting value="{!this}" marks this as a value event. You should always use this setting for an init event.

farukh sk hdfarukh sk hd
Hi this will help you ,


Please mark it as best solutiuon if this helps you.
Ajay K DubediAjay K Dubedi
Hi Vijay,
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.

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