function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
SFDC Forum 9SFDC Forum 9 

how to use attribute from one compenent to another

I  have list type attribute in lightning component1.On compoent load, list will get some values from apex method.


Now I have another component.I will click on menu item in the menubar, code as below.
<lightning:buttonMenu alternativeText="Toggle menu" label="Partcipant Info" onselect="{!c.doRedirect}" >
 <lightning:menuItem label="Home Page" value="menuitem1" iconName="utility:table"/>
          <lightning:menuItem label="Account Balance" value="menuitem2" iconName="utility:table" />

</lightning:buttonMenu>

So in doRedirect.js, i need to get compoent1 list type attribute.

Note:Both compoents are on same page.
David Zhu 🔥David Zhu 🔥
You may use lightning component application event to pass parameters between components on the same page.

Please follow the steps in the developer guide.

https://developer.salesforce.com/docs/atlas.en-us.lightning.meta/lightning/events_application.htm
 
ranbir das 1ranbir das 1
You can do this using the application event in aura component.
Step 1: Create an event.The ceEvent.evt component event has one attribute. We’ll use this attribute to pass some data in the event when it’s fired.
<! — c:ceEvent →
<aura:event type=”APPLICATION”>
<aura:attribute name=”message” type=”String”/>
</aura:event>

Step 2: Create a Notifier Component
The c:ceNotifier component uses aura:registerEvent to declare that it may fire the component event.
The button in the component contains an onclick browser event that is wired to the fireComponentEvent action in the client-side controller. The action is invoked when you click the button.
<aura:component>
<aura:registerEvent name=”cmpEvent” type=”c:ceEvent”/>
<h1>Simple Component Event Sample</h1>
<p><lightning:button label=”Click here to fire a component event” onclick=”{!c.fireComponentEvent}” /></p>
</aura:component>

//------below are the JS
/* ceNotifierController.js */
{
fireComponentEvent : function(cmp, event) {
// Get the component event by using the
// name value from aura:registerEvent
var cmpEvent = cmp.getEvent(“cmpEvent”);
cmpEvent.setParams({
“message” : “A component event fired me. “ + “It all happened so fast. Now, I’m here!” });
cmpEvent.fire();
}
}
Create Handler component
<aura:component>
<aura:attribute name=”messageFromEvent” type=”String”/>
<aura:attribute name=”numEvents” type=”Integer” default=”0"/>
<! — Note that name=”cmpEvent” in aura:registerEvent
in ceNotifier.cmp →
<aura:handler name=”cmpEvent” event=”c:ceEvent” action=”{!c.handleComponentEvent}”/>
<! — handler contains the notifier component →
<c:ceNotifier />
<p>{!v.messageFromEvent}</p>
<p>Number of events: {!v.numEvents}</p>
</aura:component>

------controller
({
handleComponentEvent : function(cmp, event) {
var message = event.getParam(“message”);
// set the handler attributes based on event data
cmp.set(“v.messageFromEvent”, message);
var numEventsHandled = parseInt(cmp.get(“v.numEvents”)) + 1;
cmp.set(“v.numEvents”, numEventsHandled);
}
})

please understand the complete dataflow between components here 
https://medium.com/@das.ranbir/lightning-aura-component-279bcf1785cd