5

I'm trying to implement a helper method in a Lightning component, but the error that comes up is:

"This page has an error. You might just need to refresh it. Error during init [Action failed: c:EmployerList$controller$doInit > [helper.getEmployerSubset_Lightning is not a function]]"

Here is my component:

<aura:component controller="EmployerListController" implements="forceCommunity:availableForAllPageTypes">
<aura:attribute name="pageIndex" type="Integer" default="0"/>
<aura:attribute name="serverData" type="EmployerListController"/>

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

<aura:iteration items="{!v.serverData.accountSubset}" var="employer">
    <c:EmployerListCell employer="{!employer}" />
</aura:iteration><br/>
<br/>
Page {!v.pageIndex+1} of {!v.serverData.numberOfPages}
<!--<lightning:button value="First" onClick="{!firstPage}"/>
<lightning:button value="Previous" onClick="{!previousPage}"/>
<lightning:button value="Next" onClick="{!nextPage}"/>
<lightning:button value="Last" onClick="{!lastPage}"/>-->

</aura:component>

And my controller init method:

({
    doInit : function(component, helper){
        console.log('getEmployerSubset_Lightning.entry');
        helper.getEmployerSubset_Lightning(component);
    }
})

And my helper method:

getEmployerSubset_Lightning : function(component) {

    var getServerDataAction = component.get("c.getEmployerListController");
    getServerDataAction.setParams({
        "pageIndex": 0
    });


    getServerDataAction.setCallback(this, function(response) {
        var state = response.getState();

        if (component.isValid() && state === "SUCCESS") {

            //Update account list
            component.set("v.serverData", response.getReturnValue());

            console.log(component.get("v.serverData.numberOfPages"));
            console.log(component.get("v.serverData.accountSubset"));

        }
        else {
            alert("error!");
        }
    });

    console.log('getEmployerSubset_Lightning.enqueueAction');
    $A.enqueueAction(getServerDataAction);

}

I can't for the life of me figure out why this wouldn't be working.

1
  • Don't you Miss à { at the beginning ? Commented Mar 24, 2017 at 23:51

1 Answer 1

18

I think the problem is with your doInit function. The helper is passed to the function as the third argument:

doInit : function(component, event, helper){
1
  • 3
    Yep, the second argument is always event, and the system is trying to call an event method that non exist. An event argument must be specified between cmp & helper.
    – Raspi
    Commented Mar 26, 2017 at 10:06

You must log in to answer this question.

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