1

i Have created one event-:

<aura:event type="COMPONENT" description="Event template" access="GLOBAL">
    <aura:attribute name="comp" type="Object"/>
</aura:event>

One application

<aura:application extends="force:slds" access="GLOBAL" useAppcache="true">
<aura:attribute name="components" type="Object[]"/>
<aura:attribute name="ShowComponent" type="Boolean" default="True"/>
<aura:handler name="compEvent" event="c:WM_Navigation" action="{!c.eventHandler}"/>

    <aura:if isTrue="{!v.ShowComponent}">
    <c:EventFirstComponent />
        </aura:if>

    <div class="slds"> 
        <div class="slds-size--1-of-1"> 
           <div class="slds">        
                <aura:iteration items="{!v.components}" var="cmp">
                    {!cmp}
                </aura:iteration>

            </div>  

            </div>
    </div>
</aura:application>

Controller

({
    eventHandler : function(component, event, helper) {
    var obj = event.getParam('comp');
        console.log('event in app builder:'+JSON.stringify(obj));        
        var componentsToBeCreated = [];
        componentsToBeCreated.push(obj);
        alert(componentsToBeCreated);
        $A.createComponents(
            componentsToBeCreated,
            function(createdComponents, status,errorMessage){
                alert('status'+status);
                if (status === 'SUCCESS') {
                    component.set("v.components", createdComponents);
                    window.scrollTo(0, 0);  
                }
                else if (status === "INCOMPLETE") 
                {
                    console.log("No response from server or client is offline.");
                }
                    else if (status === "ERROR") 
                    {
                        console.log("Error: " + JSON.stringify(errorMessage));
                    }



            });
    },
})

first component

<aura:component >
  <aura:registerEvent name="compEvent" type="c:WM_Navigation"/>
   Hello Welcome to Event Component.
   <lightning:button variant="brand" label="Submit" onclick="{!c.handleClick }" />
</aura:component>

Controller

({
    handleClick : function(component, event, helper) {
       var compEvt = component.getEvent("compEvent");

       // compEvt.setParams({"comp":["c:EventSecondComponent"]});
       alert('Enent fi');
        compEvt.setParams({"comp":["c:EventSecondComponent" ,{}] }) ;
        alert('Enent else');
        compEvt.fire();

    }
})

when i am firing this event i am getting this error

Error: [{"status":"ERROR","message":"An internal server error has occurred\nError ID: 41061075-30796 (-488974888)"}]

2 Answers 2

0
  1. did you registerEvent on the sending child component
  2. do you have event handler on the parent component you cant fire component in the .setParams only attribute, it should look something like this

     var myEvent = component.getEvent("EventName");
     myEvent.setParams({ attributeName: attributeName });
     myEvent.fire();
    
0

In your EventFirstComponent controller you are passing c:EventSecondComponent as parameter. So you are passing a Component as the parameter to be added dynamically in the application.

compEvt.setParams({"comp":["c:EventSecondComponent" ,{}] }) ;

Please check whether EventSecondComponent is already present in the Org. If not then you have to create it. It will solve the internal server error.

You must log in to answer this question.

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