When calling an Apex server-side controller, you're required to enqueue an asynchronous action, with a callback to consume the result. In the code that you shared, theresult
is not the result of the Apex call, but a reference to the action that your JavaScript controller may enqueue.
From the documentation, here's a schematic and rather verbose example of how that works:
({
"echo" : function(cmp) {
// create a one-time use instance of the serverEcho action
// in the server-side controller
var action = cmp.get("c.serverEcho");
action.setParams({ firstName : cmp.get("v.firstName") });
// Create a callback that is executed after
// the server-side action returns
action.setCallback(this, function(response) {
var state = response.getState();
if (state === "SUCCESS") {
// Alert the user with the value returned
// from the server
alert("From server: " + response.getReturnValue());
// You would typically fire a event here to trigger
// client-side notification that the server-side
// action is complete
}
else if (state === "INCOMPLETE") {
// do something
}
else if (state === "ERROR") {
var errors = response.getError();
if (errors) {
if (errors[0] && errors[0].message) {
console.log("Error message: " +
errors[0].message);
}
} else {
console.log("Unknown error");
}
}
});
// optionally set storable, abortable, background flag here
// A client-side action could cause multiple events,
// which could trigger other events and
// other server-side action calls.
// $A.enqueueAction adds the server-side action to the queue.
$A.enqueueAction(action);
}
})
In your code, c.get_doorSwing
corresponds to c.serverEcho
in the example; it's a reference to the server action. The example includes both (a) the callback function you'll have to implement to consume the result and (b) the critical synchronous call to $A.enqueueAction()
. If you don't make that call, your server action will never be executed.