[英]Closing a modal
I'm having rough times trying to close a modal with angularjs. 我在艰难的时期试图用angularjs关闭模态。
What I'm doing is open a simple modal when an event is triggered, do something inside the modal and then confirm or abort the operation. 我正在做的是在触发事件时打开一个简单的模态,在模态内执行一些操作,然后确认或中止操作。
The first opiton goes fine but when I click on the "Abort" button to close the modal the compilator says that close() is not a function. 第一个选项很好,但是当我单击“中止”按钮以关闭模态时,编译器说close()不是函数。
I thought it was an instance problem so I created one and assigned the open() and close() methods to it but nothing changed... 我以为这是一个实例问题,因此我创建了一个实例并为其分配了open()和close()方法,但没有任何改变。
Here's the JS code: 这是JS代码:
angular.module("docAcquire.controllers")
.controller('HomeController', ['$scope', '$modal', function ($scope, $modal) {
$scope.modalInstance = $modal;
$scope.openDoc = function() {
$scope.modalInstance = $modal.open({
templateUrl: 'partials/modals/Doc.html',
controller: '',
size : 'lg',
backdrop: 'static',
keyboard: false,
resolve: {}
});
};
$scope.abortOperation = function() {
$scope.modalInstance.close();
};
}
What am I doing wrong?! 我究竟做错了什么?!
EDIT: if you're going to downvote the question at least be man enough to explain why... 编辑:如果您要否决这个问题,至少要有足够的男人来解释原因...
Yor didn't add $modalInstance in your controller. 您没有在您的控制器中添加$ modalInstance。 You have two way to close modal
您有两种方式可以关闭模态
$scope.openDoc = function() {
$scope.modalInstance = $modal.open({
templateUrl: 'partials/modals/Doc.html',
size : 'lg',
backdrop: 'static',
keyboard: false,
resolve: {},
controller: ['$scope', '$modalInstance',
function($scope, $modalInstance){
//First Way
$scope.abortOperation = function() {
$modalInstance.close();
};
//Second Way
$scope.abortOperation = function() {
$modalInstance.dismiss('cancel');
};
}]});
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.