3

Using component.getReference("c.thisComponentFunction") to grab a reference for dynamically created components is a known feature. I'm not finding any documentation (or possibility) to do the same for a helper function for the same component.

Controller:

({
  doSomething : function(component, event, helper) {
    component.getReference("c.doSomethingElse"); //regular usage
    //component.getReference("helper.somethingElseInHelper"); //doesn't work
  },
  doSomethingElse : function(component, event, helper) {
    helper.somethingElseInHelper(component);
  },
})

Helper:

({
  somethingElseInHelper : function(component) {
    alert("you're in the helper!");
  },
})

Is there a way to directly access "helper.somethingElseInHelper" with component.getReference()?

1
  • Looks like the answer is "No, unless you're extending a component" which kind of defeats the purpose. It's easier to just add a dispatcher function on the component to its helper.
    – tsalb
    Nov 2, 2017 at 17:19

1 Answer 1

3

You cannot directly access a helper of another component unless you are extending it. You will need to create a controller method to give access to a helper method.

3
  • Edited for clarity and what I want to achieve. I'm in the same component, can you clarify what you mean by extending it?
    – tsalb
    Nov 1, 2017 at 6:20
  • 1
    Check this one out for extending components , developer.salesforce.com/blogs/developer-relations/2015/03/…
    – Sumuga
    Nov 1, 2017 at 9:29
  • That's a great feature. I'm not seeing it apply directly to my use case unless I basically have a component with only helpers - and extend THAT for my component.getReference("c.someHelperFunction"). I guess that's the workaround.
    – tsalb
    Nov 1, 2017 at 18:05

You must log in to answer this question.

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