6

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) {
  cmp.get('myVar'); 

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' />

1 Answer 1

7

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

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

Docs: Attribute Access Control

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .