Closed sudhirjena closed 7 years ago
Hello,
you can pass arguments to the close
method: $ocModal.close(newCustomer);
. And then in your main controller that opens the modal you can use the onClose
callback:
function openAddCustomerModal() {
$ocModal.open({
url: 'js/app/customer-add.html',
controller: 'CustomerAddController',
closeOnEsc: false,
init: {
customer: {}
},
onClose: function(newCustomer) {
}
});
}
You can pass as many arguments as you wish to the close method, they will be passed to the onClose callback.
Thanks for your quick help @ocombe ...
One more question related to your answer - Can i use vm.addNewCustomer(newCustomer) instead of an anonymous function function(newCustomer)?
function openAddCustomerModal() {
$ocModal.open({
url: 'js/app/customer-add.html',
controller: 'CustomerAddController',
closeOnEsc: false,
init: {
customer: {}
},
onClose: vm.addNewCustomer
});
}
Absolutely :)
I have a MainController that has list of customers called
vm.customers
MainController
The MainController uses $ocModal to open up an add new customer modal which is an input form with SAVE and CANCEL buttons.
The SAVE action calls dataservice.createCustomer($scope.customer) followed by $ocModal.close();
CustomerAddController
How do I pass
newCustomer
back to MainController on $ocModal.close so that a function in MainController like shown below can push the receivednewCustomer
tovm.customers
?