angularjs $ modal关闭模态 [英] angularjs $modal close modal
问题描述
我正在尝试提供angularjs Modal服务.我有一个打开某些模态的控制器,在该模态中,我调用原始控制器函数或访问一些变量,这部分我已经可以做到了.我只是不能不单击取消"或确定"按钮而关闭模态,所以要在模态中进行一些操作,手动调用一些werbservices和关闭模态.谁能帮我吗?
Im trying to make an angularjs Modal service. I have an controller that opens some modal, in that modal i call original controller functions or access some variables, this part i can make it already. I just cant close modal without clicking cancel or ok buttons, o want to make some operations in the modal, call some werbservices and the close modal manually. Can anyone help me?
我在这里制作了一个工作的柱塞:朋克车
I made an working plunker here: plunker
var modalInstance = $modal.open({
templateUrl: 'myModalContent2.html',
controller: ModalInstanceCtrl,
size: size,
scope: $scope
});
推荐答案
要关闭已打开的$ modal,可以按照以下步骤操作.
To close a $modal that you have opened you can follow these steps.
1)将 $ modalInstance
注入创建模态时指定的控制器中.在您的情况下,您将其称为 ModalInstanceCtrl
.
1) Inject $modalInstance
into the controller that you specified when you created the modal. In your case you called it ModalInstanceCtrl
.
2)在您的 ModalInstanceCtrl
中有一个函数,该函数调用 $ modalInstance
上的 .close()
.
2) Have a function in your ModalInstanceCtrl
that calls .close()
on $modalInstance
.
您的 ModalInstanceCtrl
应该看起来像这样
angular.module('myCoolApp')
.controller('ModalInstanceCtrl', function ($scope, $modalInstance) {
$scope.closeModal = function(){
$modalInstance.close();
}
});
这篇关于angularjs $ modal关闭模态的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!