[SalesForce] Define many function in afterScriptsLoaded in Lightning Component

I have two function that need to be initialized in afterScriptsLoaded.I tried define as below but it prompt error.

 <ltng:require scripts="/resource/unid__jQuery,/resource/unid__highchart" afterScriptsLoaded="{!c.generateChart},{!c.readData}" />

The error is:

Failed to save undefined: Cannot mix expression and literal string in
attribute value, try rewriting like {!'foo' + v.bar}: Source

How to define more function in afterScriptsLoaded ?

Best Answer

afterScriptsLoaded event can call only single method as far as I got from the salesforce doc. You can't call multiple method from that event but if you want to call your second method from your first method you can use following code.

  1. Controller.js

    ({  
    generateChart : function(component, event, helper) {
    
    console.log('first script called');
    component.secondmethod();
    },
    readData: function(cmp, event) {
     console.log('second script called');
    },
    
    })
    
  2. component.cmp

    <ltng:require scripts="/resource/unid__jQuery,/resource/unid__highchart" afterScriptsLoaded="{!c.generateChart}"/>
    <aura:method name="secondmethod" action="{!c.readData}" access="PUBLIC"></aura:method>
    
Related Topic