Activity › Forums › Salesforce® Discussions › Init() in salesforce
Tagged: Lightning Application, Salesforce Aura, Salesforce Controller, Salesforce Lightning, Salesforce Lightning Components
-
Init() in salesforce
Posted by madhulika shah on July 16, 2018 at 1:35 PMWhat does init() do in Salesforce lightning?
Parul replied 7 years, 8 months ago 4 Members · 3 Replies -
3 Replies
-
Hello Madhulika,
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)
- [adinserter block='9']
-
Hi,
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’);
}
})Hope this 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.