I am trying to call a controller function from a regular html button. However, I am having a hard time getting access the the controller.
I have this:
<button id="btn">My Button</button>
I have this from the scripts loaded function:
scriptsLoaded: function(component, event, helper) {
new myClass(controller, helper);
}
Then is a static Javascript library I have:
var myClass = (function() {
function myClass(controller, helper) {
this.controller = controller;
this.helper = helper;
this.helper.doAction(this.controller);
$("#id").click(function() {
this.helper.doAction(this.controller);
});
}
));
Finally in my helper I have:
doAction: function(controller) {
var action = component.get("c.fetchData");
action.setCallback(this, function(response) {
// Never reach here from click handler
var returnResponse = response.getReturnValue();
console.log(returnResponse);
broadcastEvent("SalesPlanEventTypes_fetchData", finalResult);
});
$A.enqueueAction(action);
}
As you see, I store the controller in an intermediate object, then, hook up the event handler to reuse that controller to make the action call in the helper function.
However, although the call works the first time, it does not work in response to the button click -- that is to say the action callback is never called.