2

I am trying to use two handler in the component, onload of the component, but its giving error, what is the way of using two handlers in lightning component,

Here is my markup:

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

Using doinit only its working fine, but just by adding another <aura:handler> it gives error. I don't have anything in my loadData method (I removed everything just to check), below is the code:

doinit : function(component, event, helper) {
     //my functionality
},
loadData : function (component, event, helper) {
      //my functionality
}

I've got something like event="aura:doneWaiting" and event="aura:waiting" but not sure when to use it.

Here is the error

enter image description here

3
  • 2
    Any time you have an error message, you should include it verbatim. Telling us you got an error but not sharing what it is makes it much more difficult to help you.
    – Adrian Larson
    Commented May 1, 2017 at 14:50
  • Also note that error messages are significantly more searchable (and therefore useful) when included as text rather than images.
    – Adrian Larson
    Commented May 1, 2017 at 15:28
  • That's actually a common error, but here its not the error, its something else, so that why posted the text. Commented May 1, 2017 at 15:31

1 Answer 1

1

According to the docs only one event handler for the this event should be present.

A component can have only one tag to handle this event. Setting value="{!this}" marks this as a value event. You should always use this setting for an init event.

If you wanted to invoke another method from the this event handler, you should be using the helper here.

controller:

doinit : function(component, event, helper) {
     //my functionality
     helper.loadData(component, event, helper);
},

helper:

loadData : function (component, event, helper) {
      //my functionality
}
3
  • So what If I want to use two handler with {!this}, can I use that ? Commented May 1, 2017 at 19:16
  • 2
    No, you cannot have two handlers for {!this} event.
    – Praveen
    Commented May 2, 2017 at 1:16
  • And what would be the reason to have 2 handlers for the same event ? Commented May 2, 2017 at 15:43

You must log in to answer this question.

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