[英]angular modal not closing ($uibModal )
angular
.module('angProj')
.controller('UserCtrl',
['$scope', '$uibModal',
function ($scope, $uibModal) {
$scope.results = function (content, completed) {
var modalInstance = $uibModal.open({
backdrop: 'static',
keyboard: false,
animation: $scope.animationsEnabled,
templateUrl: '/Scripts/angularApp/views/user-modal.html',
controller: 'UserModalCtrl',
resolve: {
items: function () {
return $scope.items;
}
}
});
if (!completed || content.length === 0) {
return;
}
modalInstance.close();
modalInstance.dismiss('cancel');
I am not able to close the model on user add completion.. On user-modal i am showing progress bar.. the code runs fine without error but the modal remains open. 我无法在用户添加完成时关闭模型。在用户模式下,我正在显示进度栏。.代码运行正常,没有错误,但模式保持打开状态。 I also tried $uibModalInstance but the controller throws error: unknown provider (not able to inject $uibModalInstance on the same UserCtrl) I am injecting ui.bootstrap (ui-bootstrap-tpls-1.1.2.js) 我也尝试了$ uibModalInstance,但是控制器抛出错误:未知提供程序(无法在同一UserCtrl上注入$ uibModalInstance)我正在注入ui.bootstrap(ui-bootstrap-tpls-1.1.2.js)
Thanks for your time. 谢谢你的时间。
Use modalInstance.close()
inside your UserModalCtrl
controller 在UserModalCtrl
控制器中使用modalInstance.close()
app.controller('UserModalCtrl', ['$scope', '$modalInstance' function($scope ,modalInstance {
$scope.close = function () {
modalInstance.close();
};
}]);
I have done something similar, I think. 我想我做了类似的事情。
I have a $modal
controller that looks like this 我有一个看起来像这样的$modal
控制器
angular.module('myApp').controller('infoCtrl', function ($scope, $uibModalInstance, loading) {
$scope.editable = loading;
$scope.$watch('editable.status', function(newValue, oldValue) {
if (newValue == 'success'){
// close modal
$uibModalInstance.close('ok');
} else if (newValue == 'error') {
// show error message
}
});
});
The injected loading
is a service that looks like this 注入的loading
是一个看起来像这样的服务
myApp.factory('loading', function() {
return {
status: ''
}
});
And when I change the status of my loading service to 'success' (from anywhere, not the modal controller) the modal is closed. 当我将加载服务的状态更改为“成功”(从任何地方,而不是模态控制器)时,模态已关闭。
I don't know if this is exactly what you were asking for, but I hope it helps, also, just ask if something is unclear! 我不知道这是否正是您要的内容,但是我希望这会有所帮助,也请问是否有不清楚的地方!
EDIT: So let's say you have a service with a value isCompleted: false
, inject that service into your modal controller, and use the $watch
function, then when that isCompleted
is changed to true
, you close the modal. 编辑:所以,假设您有一个值为isCompleted: false
的服务isCompleted: false
,将该服务注入到模态控制器中,并使用$watch
函数,然后当isCompleted
更改为true
,关闭模态。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.