Activity › Forums › Salesforce® Discussions › What is the init() function in Salesforce Lightning?
-
What is the init() function in Salesforce Lightning?
Posted by sushant on December 22, 2016 at 2:13 PMHi All,
What is the init() function in Lightning?
please give suggestions
Thanks
Parul replied 7 years, 8 months ago 5 Members · 5 Replies -
5 Replies
-
Hi Sushant,
This event is automatically fired when an app or component is initialized, prior to rendering.
Component-
<aura:component>
<aura:handler name=”init” value=”{!this}” action=”{!c.doInit}”/>
</aura:component>
jsController-
({
doInit: function(cmp) {
// Set the attribute value.
// You could also fire an event here instead.
alert(‘test’);
}
})Thanks
- [adinserter block='9']
-
Hi,
We use Init() event to initialize a component or fire an event after component construction but before Rendering.
aura:init always runs first, as it runs the moment the component is constructed.
In component source we use-
<aura:handler name=”init” value=”{!this}” action=”{!c.doInit}”/>
Client side Controller source we use-
doinit:function(component,event,helper)
Hope it helps.
-
Hi.
<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.THanks
Log In to reply.