Reputation: 9184
I'm using modals via method, like:
this.showModal = function () {
return $uibModal.open({...});
}
and then in some method i call this function:
this.showModal().result.then(function (someResult) {...});
but how can i use dismiss, using method call?
becouse i use it without method, i can close my modal so:
$uibModal.open({...}).result.then(function (someResult) {
this.$dismiss();
})
but i have no clue, how to use dismiss, when i use methods promise...
maybe somebody have an idea?
Upvotes: -1
Views: 1339
Reputation: 15292
The open method returns a modal instance with open, closed,dismiss ,close,rendered ,returned
method.
In your case it is this.showModal
is modal instance.
SO, you can call the close the method like this.
var self = this;
self.showModal = function () {
return $uibModal.open({...});
}
//close the modal
self.showModal.close();
Upvotes: 1
Reputation: 149
What I usually do is making a modal instance :
$scope.doSomething = function(){
var modalOptions = {...};
openModal(modalOptions);
}
function openModal(modalOptions) {
$scope.myModalInstance = $uibModal.open(modalOptions);
$scope.myModalInstance.result.then(function () {
//success callback
}, function () {
//error callback;
});
}
Later if i want to call close or dismiss simply call $scope.myModalInstance.close()
and $scope.myModalInstance.dismiss('cancel')
.
Upvotes: 0
Reputation: 16801
You could store the modal in an object, either in the scope or move this to a service, and then call dismiss on the modal object
var modalInstance;
this.showModal = function () {
modalInstance = $uibModal.open({...});
return modalInstance;
}
and when using the promise
this.showModal().result.then(function (someResult) {
modalInstance.dismiss('cancel');
});
Upvotes: 0