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
Alex Dinu 17Alex Dinu 17 

Set an attribute value in helper

I'm trying to code a pure function, passing in the component into the helper method and setting:

In the component, I have the following defined:
<aura:attribute name="teamCount" type="integer" default="1"/>
in the controller, I'm trying to do the following:
helper.onSetTeamCountRequest( component.get("v.teamCount"));
And in the helper, I want to change the value:
 
onSetTeamCountRequest: function( teamCountAttribute) {
        teamCountAttribute = 5;
    },

But it does not update the value.

Thanks


 
Best Answer chosen by Alex Dinu 17
Alain CabonAlain Cabon
You are using the Aura framework and it is this Javascript API describes here:

http://documentation.auraframework.org/auradocs#reference?topic=api:Component

You can only use Component as parameter here with get / set functions as you already done.
I have had the same apprehension at first but I built big components passing always components and Inever had a problem of memory.

component.get("v.teamCount") just returns the value "5" (not the reference to the component itself attribute which doesn't have an accessible attribute "value" either but just a default value). 

There are three kind of attribute: Function, Object and Basic. 
If you get an object and change a value of an attribute, you always need a component.set('v.myObject', myModifiedObject); at the end, if you want to see the change on your form.

 

All Answers

Alain CabonAlain Cabon
Hi,
 
helper.onSetTeamCountRequest( component );
onSetTeamCountRequest: function( component ) {
        component.set('v.teamCount', 5);
},
Alex Dinu 17Alex Dinu 17
Thanks. Thats waht we do, but I was trying not to send in the whole component, but rather just the sub component\attribute.

Alex
 
Alain CabonAlain Cabon
You are using the Aura framework and it is this Javascript API describes here:

http://documentation.auraframework.org/auradocs#reference?topic=api:Component

You can only use Component as parameter here with get / set functions as you already done.
I have had the same apprehension at first but I built big components passing always components and Inever had a problem of memory.

component.get("v.teamCount") just returns the value "5" (not the reference to the component itself attribute which doesn't have an accessible attribute "value" either but just a default value). 

There are three kind of attribute: Function, Object and Basic. 
If you get an object and change a value of an attribute, you always need a component.set('v.myObject', myModifiedObject); at the end, if you want to see the change on your form.

 
This was selected as the best answer
Alex Dinu 17Alex Dinu 17
Thank you. It's not the memory I'm worried about. I want to test the method and it's just easier to only pass in what it needs. Not a bit issue, but I was just wondering.....