Reputation: 11
I have a input box in modal popup , i want that value in my main controller which invoked the modal.
Upvotes: 1
Views: 626
Reputation: 1061
Easy way:
//Modal controller
$rootScope.$broadcast('modal:nameOfModal:onSave', { data: data })
//Any other controller
$scope.$on('modal:nameOfModal:onSave', function(event, data) { ... } )
Right way:
Factory
with methods representing each modal type you needFactory
(like Factory.confirmationWindow()
) returning a promise
that should be handled separately in controllers that rise appropriate modalCall something like in your controller
Controller.propotype.openModal = function() {
ModalsFactory.confirmationModal().then(function(result) {
//using result inside of your controller
//if clicked ok
}).catch(function() {
//behavior to be called when modal canceled
});
}
Pros:
Cons:
ModalsFactory
will be big fileUpvotes: 1