0

I want to send a parameter in a hidden manner from one component to another in salesforce lightning. The normal Syntax would be this -

 navigate : function(component, event, helper) {

    //Find the text value of the component with aura:id set to "address"
    var address = component.find("address").get("v.value");

    var urlEvent = $A.get("e.force:navigateToURL");
    urlEvent.setParams({
      "url": 'https://www.google.com/maps/place/' + address
    });
    urlEvent.fire();
}

but I need to pass the param value in a hidden way . Suggest answer .

1 Answer 1

0

Take a look at the documentation for communicating with events here.

Depending on the hierarchy of your components you would use either an application event or a component event. An example of passing a parameter through an application event would be:

The event file:

<!--c:appEvent-->
<aura:event type="APPLICATION">
    <!-- pass context of where the event was fired to the handler. -->
    <aura:attribute name="context" type="String"/>
</aura:event>

In the component originating the parameter include the following in the html:

<aura:registerEvent name="appEvent" type="c:appEvent"/>

and in the controller of that component, add the parameter and fire it:

var appEvent = $A.get("e.c:appEvent");
appEvent.setParams({ "context" : parentName });
appEvent.fire();

Then in the component where you want to receive the event, include in the html:

<aura:handler event="c:appEvent" action="{!c.handleApplicationEventFired}"/>

And in the controller of the component include the function to handle the event:

handleApplicationEventFired : function(cmp, event) {
    var context = event.getParam("context");
    cmp.set("v.mostRecentEvent", 
        "Most recent event handled: APPLICATION event, from " + context);

    var numApplicationEventsHandled =
        parseInt(cmp.get("v.numApplicationEventsHandled")) + 1;
    cmp.set("v.numApplicationEventsHandled", numApplicationEventsHandled);
}

Note that the syntax for using component events is different.

You must log in to answer this question.

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