I am trying to use Promise to make my code more readable and efficient but I'm stuck with the inability to get/set private attribute values. Consider the following example:


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

    <aura:handler name="init" value="{!this}" action="{!c.doInit}"/>

The doInit logic:

    doInit: function(cmp, event, helper) {

            .then(function(message) {
                cmp.set("v.message", message);

I am unable to set or get a value for the message attribute. However, if I remove the access="private" property the code works.

I found a similar question here but according to the answer - if locker service was the problem - it should have been fixed already.


I answer my own question. I forgot to use $A.getCallback() to grant the correct access level to the asynchronous code.

The code should be:

    .then($A.getCallback(function(message) {
        cmp.set("v.message", message);
| improve this answer | |
  • 1
    Your post just saved me from removing access="private" from a bunch of components. Thanks! – Keith C Jan 12 '18 at 10:59
  • damn, I really need to remember putting that in my promises :D Think this is the 4th time that your post solves my problem – Nielsm Jun 6 '18 at 11:09

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.