I'm wondering how I can prevent copying code in the following code. I copied the function wishModel.createWish()
. The reason to copy the code is:
- in the if-part the function must be triggered after a promise (a modal is opened) is resolved
- in the else-part the function is executed immediately
Thanks for helping me improve my code!
if (copyExistsOnList) {
var copyWarningPopup = $uibModal.open({...});
copyWarningPopup.result.then(function (wish) {
wishModel.createWish(newWish, userID, userID, wish._id);
});
} else {
wishModel.createWish(newWish, userID, userID, wish._id);
}