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
Kanhaiya Yadav 4Kanhaiya Yadav 4 

Regarding to Lighting Development.

Hi,

I am new in lightning. I am making one module in lightning, which have 4 or 5 buttons to do different activities. Should I create different component for each button or developments in the same (Base) component.


Thanks & Regards,
Kanahaiya
Sandeep YadavSandeep Yadav
Hi Kanhaiya,

You can define 4-5 or more buttons in a single component with different unique Id and can write your logic into controller by getting the reference of a particulae with the help of aura:id .
<lightning:button aura:id="btn1" label="Button1"/>
<lightning:button aura:id="btn2" label="Button2/>
Regards
Sandeep Yadav
 
Kanhaiya Yadav 4Kanhaiya Yadav 4
Hi Sandeep,

   Thanks for reply. 
   My question was,  should i create different component for each button or write code in base component ?.

Suppose i have 3 buttons add, edit, some other .
  <lightning:button variant="brand" label="New" title="new" onclick="{! c.AddProduct}" />   
  <lightning:button variant="brand" label="Edit" title="new" onclick="{! c.EditProduct}" />   
    <lightning:button variant="brand" label="Delete" title="new" onclick="{! c.DeleteProduct}" />   

       What is best practices ? 
       Create different components for each action  Or Write code in same component(Base Component). ?      
             

Thanks,
Kanhaiya
Sandeep YadavSandeep Yadav
HI kanhaiya
No, There is no need for creating different component for different button.
Your action goes in javascript controller and you can define more than one method in controller section by seperating them with comma.