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
Bvenkat Jeewesh(Dev)Bvenkat Jeewesh(Dev) 

How to get value from Helper.js to Controller.js in Lightning Component

How to get value from Helper.js to Controller.js in Lightning Component
Ravi Dutt SharmaRavi Dutt Sharma
Set the value in an attribute in helper and fetch the value of that attribute in controller
Ajay K DubediAjay K Dubedi
Hi Bvenkat,
The Simplest way to get value from helper to controller is to create an aura attribute in component and set value of the particular attribute in 
Helper. Then you can get value of that attribute in your controller.

For Example:
In Component you need to add:
<aura:attribute name="myAttribute" type="String"/>

In Helper you need to add:
c.set("v.myAttribute",'Demo');

In Controller you can get value by this:
var myValue=c.get("v.myAttribute");
 

I hope you find the above solution helpful. If it does, please mark as Best Answer to help others too.
Thanks,
Ajay Dubedi
Deepali KulshresthaDeepali Kulshrestha
Hi Bvenkat,
Greetings to you!

- You can use an attribute for lightning to get and set the value, which helps you to get value from Helper.js to Controller.js in Lightning Component
- First, you have to make an attribute on the lightning component.

 <aura:attribute name="name" type="String" access="global"/>

- Then in Helper.js, you have to set the value in attribute 'name'.

    component.set('v.name','Bob');
    
- Then in Controller.js, you can get the value of attribute 'name'.

    let valueOfName = component.get('v.name');
    
- To check the value you can use : -  console.log('valueOfName-->'+valueOfName);

I hope you find the above solution helpful. If it does, please mark as Best Answer to help others too.

Thanks and Regards,
Deepali Kulshrestha.