Activity › Forums › Salesforce® Discussions › How to get Attribute from one component to another component in Salesforce?
Tagged: Aura Attribute, Aura Component, Aura RegisterEvent, Lightning Controller, Salesforce Components, Salesforce Controller
-
How to get Attribute from one component to another component in Salesforce?
Posted by Deepak on August 12, 2019 at 2:54 PMHow to get an Attribute from one component to another component in Salesforce?
Piyush replied 6 years, 10 months ago 2 Members · 1 Reply -
1 Reply
-
Hi Deepak,
Try this code to get an attribute from one component to another component:-
//First component
<aura:component> <aura:attribute name=”recordId” type=”Id” /> <aura:handler name=”init” value=”{!this}” action=”{!c.doInit}” /> <aura:attribute name=”wrappers” type=”ListeArticlesWrapper” /> <aura:attribute name=”articles” type=”Article__c” /> <aura:attribute name=”Detail” type=”String”/> <aura:registerEvent name=”navigate” type=”c:NavigateToDetail”/> <div class=”page”> <h1>Liste des articles</h1> <div class=”slds”> <table class=”slds-table slds-table–bordered slds-table–cell-buffer”> <thead> <tr class=”slds-text-heading–label”> <th scope=”col” class=”head”></th> <th scope=”col” class=”head”>Nom</th> <th scope=”col” class=”head”>Type</th> <th scope=”col” class=”head”>Prix</th> <th scope=”col” class=”head”></th> </tr> </thead> <tbody> <aura:iteration items=”{!v.wrappers}” var=”wrap”> <tr> <td class=”cell”> <ui:inputCheckbox value=”{!wrap.selected}” /> </td> <td class=”cell”> <ui:outputText value=”{!wrap.art.Name}” /> </td> <td class=”cell”> <ui:outputText value=”{!wrap.art.Type__c}” /> </td> <td class=”cell”> <ui:outputText value=”{!wrap.art.Prix__c}” /> </td> <td class=”cell”> <button class=”slds-button slds-button–neutral slds-not-selected” onclick=”{!c.getDetail}” data-recId=”{!wrap.art.Id}”>Details</button> </td> </tr> </aura:iteration> </tbody> </table> </aura:component>//Controller of this component
doInit : function(component, event, helper) { helper.init(component, event); }, getArticles : function(component, event, helper) { helper.getArticles(component, event); }, getDetail : function(component, event, helper) { var id = event.target.getAttribute("data-recId"); var article = component.get("v.articles"); var evt = $A.get("e.c:NavigateToDetail"); evt.setParams({"detail": article});evt.fire(); }Just like create the second component.
Thanks
Piyush
Log In to reply.