Activity Forums Salesforce® Discussions What is the init() function in Salesforce Lightning?

  • Satyakam

    Member
    January 4, 2017 at 2:22 pm

    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

  • sushant

    Member
    January 5, 2017 at 5:50 am

    Thanks

  • CloudGenie

    Member
    January 6, 2017 at 7:15 am

    Nice Solution

  • shariq

    Member
    September 18, 2018 at 1:26 am

    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.

  • Parul

    Member
    September 18, 2018 at 2:48 am

    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.

Popular Salesforce Blogs