5

We had following code in our component controller of a complex application-

window.setTimeout(helper.hideSpinner(component, helper), 500);

Functionality works but give an error as displayed at the bottom of the page:

Bind must be called on a function

1 Answer 1

10

Resolution-

  1. If set timeout modifies any attributes, use $A.callback-

     window.setTimeout(
         $A.getCallback(function() {
             helper.hideSpinner(component, helper)
         }), 
         500
     );
    
  2. As per setTimeout documentation, use any one of the following if calling function doesn't modifies any attributes:

     window.setTimeout(
         function() { 
             helper.hideSpinner(component, helper)}, 
         500
     );        
    
     // or send function and arguments separately 
     window.setTimeout(
         helper.hideSpinner, 
         500, component, helper
     );
    

I searched on internet and didn't find any issues. We burned couple of hour to identify the cause because error message was not clear enough; at-least to us. Sharing it hereby in case some else is stuck with this problem.

1
  • 2
    The $A.getCallback method is required if hideSpinner modifies any attributes of the component, but if you're just toggling a CSS class, then $A.getCallback is not required.
    – sfdcfox
    Jan 26, 2018 at 15:48

You must log in to answer this question.

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