according to the https://angular-ui.github.io/bootstrap/#/modal, I want to pass a result from modal to the parent without closing but in the example code, they only show a passing result to parent via closing
$uibModalInstance.close($scope.selected.item);
I want to pass a data to parent when the item is clicked but I do not know to do it. I really need help. Thanks.
This is a quite common problem about communicating between controllers since you don't want to close the model and wants to pass the data to a different controller.
The quickest path to your problem is using $broadcast
. In the controller of your modal, write like this:
// Make sure to use $rootScope
$rootScope.$broadcast("modalDataEventFoo", {selectedItem: $scope.selected.item});
Now, in your parent controller:
$scope.$on("modalDataEventFoo", function(event, data) {
console.log("got the data from modal", data.selectedItem);
});
Other references for communication between controllers:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With