We use aura:attribute to share values between controllers and helpers, but this exposes the variable to parents components, because a parent component can set the value. How can I declare something like a private variable? Do you have any idea?

An example MyComponent

<aura:attribute name="myVar" type="Object"/>

My controllers use myVar

action1 : function (cmp ) {
  cmp.set("v.myVar, 'some value');

action2 : function (cmp) {

But other components can set my attribute in this way. I don't want this. Example

<c:MyComponent myVar='I don't want set myVar here' />

In your MyComponent definition, specify access="private" for your attribute.

<aura:attribute name="myVar" type="Object" access="private"/>

Docs: Attribute Access Control

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.