• Pankaj Singh 54
  • NEWBIE
  • 0 Points
  • Member since 2016

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 1
    Questions
  • 1
    Replies
<aura:event type="APPLICATION" description="Add to cart event.">
    <aura:attribute name="product" type="string"/>
</aura:event>

<aura:component implements="force:appHostable">
    <aura:registerEvent name="addToCartEvent" type="c:AddToCart"/>
<ui:inputText aura:id="n1" label="Number1" required="true"/>
<ui:inputText aura:id="n2" label="Number2" required="true"/>
<ui:button label="Sum" press="{!c.Add}"/>
</aura:component>

i try to navigate with attribute value but i am not able to navigate. ​


({

   Add : function(component, event, helper) {
           debugger;
   var num1 = component.find("n1").get("v.value");
   var num2 = component.find("n2").get("v.value");
   var res = parseInt(num1) + parseInt(num1);
   res = res + '';

        var evt = $A.get("e.force:AddToCart");
       evt.setParams({
        "product": res
       });
       
   evt.fire();
   }
})


<aura:component >
     <aura:handler event="c:AddToCart" action="{!c.handleApplicationEvent}"/>
  <aura:attribute name="res" type="String" />
   
 <!-- <aura:handler event="c:Result" action="{!c.handleApplicationEvent}"/>-->
  The result is {!v.res}
</aura:component>


({
handleApplicationEvent : function(cmp, event) {
    debugger;
      var product = event.getParam("product");
       // set the handler attributes based on event data
       cmp.set("v.res", ResultValue);
   }
})
How to navigate between Lightning components and pass value between them? Please explain with example.