4

With the following markup we create an action handler that is "fired" when the component is first loaded.

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

Can someone tell me which part of the above markup actually tells this behaviour to happen ?

Is it the name="init" attribute or this value="{!this}" ?

I assume action just indicates the method to be called invoked from the client side controller and this can be anything like

c.xyz

or

c.abc

1
  • as far as I know; it's both! The handler 'activates' when the value specified (ie 'this') is initialised
    – Aequitas
    Feb 14, 2018 at 0:32

2 Answers 2

13

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.

3

aura:valueInit event is automatically fired when an app or component is initialized, but before rendering. The part name="init" tag handles this.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .