I'm new to Salesforce. I have just started with lightning Aura components. I want to understand simple workflow of aura. Can anyone help me with the code for below requirement. Thanks in advance.
Requirement. I have two custom components. One component has list of custom object records. Another component has detail page of that record. Onclick of record in the first component it should navigate to second component by passing Id and display current record details.
Sample code attached; Component1.cmp:
<aura:component implements="force:appHostable,flexipage:availableForAllPageTypes"><aura:attribute name="Result" type="String"/>
<lightning:navigation aura:id="navService"/>
<ui:inputText aura:id="n1" maxlength="5" size="5" label="Number1" required="true"/>
<ui:inputText aura:id="n2" maxlength="5" size="5" label="Number2" required="true"/>
<ui:button label="Sum" press="{!c.Calculate}"/></aura:component>
Component1.js
({Calculate : function(component, event, helper) {
var a = component.find("n1").get("v.value");
var b = component.find("n2").get("v.value");
var res = parseInt(a) + parseInt(b);
res = res + '';
component.find("navService").navigate({
"type": "standard__component",
"attributes": {
"componentName": "c__Component2"
},
"state": {
"res":"5"
}
});
} })
Component2.cmp
<aura:component implements="force:appHostable,flexipage:availableForAllPageTypes,lightning:isUrlAddressable"><aura:attribute name="res" type="String" />The result is {!v.res}</aura:component>