You need to sign in to do that
Don't have an account?

how to get one component's attribute in another component in lightning component
Hi Friends
I am facing a issue with how can to get one components attribute value to another component
I have Two components 1) FormComponent and 2) PrintComponent
I need FormComponent's OppId attribute in PrintForm's Java script controller.
How can i get the attribute?
Below is the code skeleton
FormComponent.cmp
----------------
<aura:component controller="FormController">
<aura:attribute name="oppId" type="String" default=""/>
<lightning:layout>
<lightning:layoutItem padding="horizontal-small" largeDeviceSize="3" mediumDeviceSize="3" smallDeviceSize="12" size="12">
<lightning:button variant="brand" label="Print Forms" title="Print Loan Agreement" onclick="{!c.printForms}" />
</lightning:layoutItem>
</lightning:layout>
</aura:component>
FormComponentcontroller.js
------------------------------
({
doInit: function(component, event, helper){
},
printForms : function(component, event, helper){
// need to send oppId to another component PrintForm
}
})
PrintForm.cmp
-------------
<aura:component implements="force:appHostable,force:hasRecordId,forceCommunity:availableForAllPageTypes,force:lightningQuickAction"
access="global"
controller="PrintController">
<aura:attribute name="oppId" type="String" default=""/>
<!-- logic to implement the datatable to view the data -->
</aura:component>
PrintFormController.js
-----------------------
{
doInit: function(component, event, helper){
// how can i get the oppId value from Form component
},
I am facing a issue with how can to get one components attribute value to another component
I have Two components 1) FormComponent and 2) PrintComponent
I need FormComponent's OppId attribute in PrintForm's Java script controller.
How can i get the attribute?
Below is the code skeleton
FormComponent.cmp
----------------
<aura:component controller="FormController">
<aura:attribute name="oppId" type="String" default=""/>
<lightning:layout>
<lightning:layoutItem padding="horizontal-small" largeDeviceSize="3" mediumDeviceSize="3" smallDeviceSize="12" size="12">
<lightning:button variant="brand" label="Print Forms" title="Print Loan Agreement" onclick="{!c.printForms}" />
</lightning:layoutItem>
</lightning:layout>
</aura:component>
FormComponentcontroller.js
------------------------------
({
doInit: function(component, event, helper){
},
printForms : function(component, event, helper){
// need to send oppId to another component PrintForm
}
})
PrintForm.cmp
-------------
<aura:component implements="force:appHostable,force:hasRecordId,forceCommunity:availableForAllPageTypes,force:lightningQuickAction"
access="global"
controller="PrintController">
<aura:attribute name="oppId" type="String" default=""/>
<!-- logic to implement the datatable to view the data -->
</aura:component>
PrintFormController.js
-----------------------
{
doInit: function(component, event, helper){
// how can i get the oppId value from Form component
},
Use the Application Event:
https://www.biswajeetsamal.com/blog/application-events-in-salesforce-lightning-framework/
1. Create Application Event: Name as passoppId
<!--passoppId.evt-->
<aura:event type="Application">
<aura:attribute name="oppId" type="String" />
</aura:event>
2. Fire the event from FormComponent
FormComponent.cmp
----------------
<aura:component controller="FormController">
<aura:attribute name="oppId" type="String" default=""/>
<aura:registerEvent name="passoppId" type="c:passoppId"/>
<lightning:layout>
<lightning:layoutItem padding="horizontal-small" largeDeviceSize="3" mediumDeviceSize="3" smallDeviceSize="12" size="12">
<lightning:button variant="brand" label="Print Forms" title="Print Loan Agreement" onclick="{!c.printForms}" />
</lightning:layoutItem>
</lightning:layout>
</aura:component>
FormComponentcontroller.js
------------------------------
({
doInit: function(component, event, helper){
},
printForms : function(component, event, helper){
// need to send oppId to another component PrintForm
var appEvent = $A.get("e.c:passoppId");
appEvent.setParams({"oppId" : component.get('v.oppId')});
appEvent.fire();
}
})
3. handle the event in PrintForm component
PrintForm.cmp
-------------
<aura:component implements="force:appHostable,force:hasRecordId,forceCommunity:availableForAllPageTypes,force:lightningQuickAction"
access="global"
controller="PrintController">
<aura:handler event="c:passoppId" action="{!c.doInit}"/>
<aura:attribute name="oppId" type="String" default=""/>
<!-- logic to implement the datatable to view the data -->
</aura:component>
PrintFormController.js
-----------------------
{
doInit: function(component, event, helper){
// how can i get the oppId value from Form component
var message = event.getParam("oppId");
component.set("v.oppId", message);
},
Thanks,
Maharajan.C
All Answers
I need to send opportunity id from the Form Controller dynamically to the Print controller when button click..and get that same opp id in printcontroller.
Use the Application Event:
https://www.biswajeetsamal.com/blog/application-events-in-salesforce-lightning-framework/
1. Create Application Event: Name as passoppId
<!--passoppId.evt-->
<aura:event type="Application">
<aura:attribute name="oppId" type="String" />
</aura:event>
2. Fire the event from FormComponent
FormComponent.cmp
----------------
<aura:component controller="FormController">
<aura:attribute name="oppId" type="String" default=""/>
<aura:registerEvent name="passoppId" type="c:passoppId"/>
<lightning:layout>
<lightning:layoutItem padding="horizontal-small" largeDeviceSize="3" mediumDeviceSize="3" smallDeviceSize="12" size="12">
<lightning:button variant="brand" label="Print Forms" title="Print Loan Agreement" onclick="{!c.printForms}" />
</lightning:layoutItem>
</lightning:layout>
</aura:component>
FormComponentcontroller.js
------------------------------
({
doInit: function(component, event, helper){
},
printForms : function(component, event, helper){
// need to send oppId to another component PrintForm
var appEvent = $A.get("e.c:passoppId");
appEvent.setParams({"oppId" : component.get('v.oppId')});
appEvent.fire();
}
})
3. handle the event in PrintForm component
PrintForm.cmp
-------------
<aura:component implements="force:appHostable,force:hasRecordId,forceCommunity:availableForAllPageTypes,force:lightningQuickAction"
access="global"
controller="PrintController">
<aura:handler event="c:passoppId" action="{!c.doInit}"/>
<aura:attribute name="oppId" type="String" default=""/>
<!-- logic to implement the datatable to view the data -->
</aura:component>
PrintFormController.js
-----------------------
{
doInit: function(component, event, helper){
// how can i get the oppId value from Form component
var message = event.getParam("oppId");
component.set("v.oppId", message);
},
Thanks,
Maharajan.C
https://developer.salesforce.com/forums/ForumsMain?id=9062I000000INdeQAG
The communication between components is handled by events. There are two types of custom events in the Lightning Framework:
Component Events
Application Events
Component events are handled by the component itself or a component that instantiates or contains the component.
Application events are handled by all components that are listening to the event. These events are essentially a traditional publish-subscribe model.
I suggest to visit this link, there is a good description of how to use the event in component for passing attribute values
https://www.biswajeetsamal.com/blog/component-events-in-salesforce-lightning-framework/
Thanks and Regards,
Deepali Kulshrestha.
@Maharajan, i have tried this also but unfortunately it does not suits for my requirement. finally i have achived with standard salesforce action $A.get('e.lightning:openFiles');.