I have a parent component with the <lightning:overlayLibrary aura:id="overlayLib"/>
component added.
The parents controller creates an instance of the modal component, assigns it to the body of the modal, and displays the modal using component.find('overlayLib').showCustomModal()
. Nothing used in the footer.
Now, inside the modal component I have two buttons, 'Cancel' and 'Save'. Cancel just closes the modal, while Save makes a callout to the apex controller, then closes the modal.
Both button methods utilize component.find("overlayLib").notifyClose();
... however, it only works for the Cancel button.
The Save button fires the notifyClose
method from the then()
function of the promise returned by the apex controller, and this seems to cause an error.
Console Log Error: There is no event definition for event "notify", probably because there is no component to handling it.
submitSaveObject : function(component, saveObj){
var action = component.get('c.saveConfiguration');
action.setParams({ "saveObj" : JSON.stringify(saveObj)});
var actionPromise = new Promise(function (resolve, reject){
action.setCallback(this, $A.getCallback( function(actionResult){
var state = actionResult.getState();
console.log('apex callback result: ');
if (state === "SUCCESS"){
var result = actionResult.getReturnValue();
resolve(result);
} else if (state === "ERROR"){
reject();
}
}));
$A.enqueueAction(action);
});
actionPromise.then(function(returnValue){
alert('Save successful!');
//this is throwing an error
component.find("overlayLib").notifyClose();
});
}
How can I successfully close the modal in such a way that it is enqueued after the asynch call to the apex controller?
notifyClose();
doesn't seem to work anymore, I usedclose();
component.find("overlayLib").close();
instead of notifyClose() I get a component error saying close() is not a function.v.modalPromise
assigned the promise returned when you first open the modal usingcomponent.find('overlayLib').showCustomModal()
?component.find('overlayLib').showCustomModal()
is fired inside the$A.createComponent()
method where I create the modal's body and also set the parameters to pass to the modal component. To use your method I'd need the promise returned byshowCustomModal
to be passed to the modal cmp as a param, so I can use the promises'then
function to get the modal obj and use theclose()
method. But how can I pass that promise as a param when it is being generated within$A.createComponent()
's callback function?