Jquery 角度模式未关闭($uibModal)
我无法在用户添加完成时关闭模型。。在用户模式下,我显示进度条。。代码运行正常,没有错误,但模式保持打开状态。我还尝试了$uibModalInstance,但控制器抛出错误:未知提供程序(无法在同一个UserCtrl上注入$uibModalInstance) 我正在注入ui.bootstrap(ui-bootstrap-tpls-1.1.2.js)Jquery 角度模式未关闭($uibModal),jquery,angularjs,modal-dialog,bootstrap-modal,ui.bootstrap,Jquery,Angularjs,Modal Dialog,Bootstrap Modal,Ui.bootstrap,我无法在用户添加完成时关闭模型。。在用户模式下,我显示进度条。。代码运行正常,没有错误,但模式保持打开状态。我还尝试了$uibModalInstance,但控制器抛出错误:未知提供程序(无法在同一个UserCtrl上注入$uibModalInstance) 我正在注入ui.bootstrap(ui-bootstrap-tpls-1.1.2.js) 谢谢您的时间。在UserModalCtrl控制器内使用modalInstance.close() angular .module('angProj')
谢谢您的时间。在
UserModalCtrl
控制器内使用modalInstance.close()
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');
我想我也做过类似的事情 我有一个
$modal
控制器,看起来像这样
app.controller('UserModalCtrl', ['$scope', '$modalInstance' function($scope ,modalInstance {
$scope.close = function () {
modalInstance.close();
};
}]);
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
}
});
});
注入的加载
是一个如下所示的服务
app.controller('UserModalCtrl', ['$scope', '$modalInstance' function($scope ,modalInstance {
$scope.close = function () {
modalInstance.close();
};
}]);
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
}
});
});
当我将加载服务的状态更改为“成功”(从任何地方,而不是模态控制器)时,模态关闭
我不知道这是否正是你所要求的,但我希望它能有所帮助,而且,只要问问是否有什么不清楚的地方就行了
编辑:假设您有一个值为
isCompleted:false
的服务,将该服务注入您的模式控制器,并使用$watch
功能,然后当该isCompleted
更改为true
,您可以关闭模式。您应该从模式控制器控制器:'UserModalCtrl'
关闭模式,并注入$uibModalInstance
there@klskl我正在做…我有一个取消按钮,它从那里关闭模式…但在进程完成后,我希望模式自动关闭…没有任何用户交互(如取消按钮单击)您应该在模态控制器中使用$uibModalInstance(在您的情况下是UserModalCtrl)…它工作正常,但我希望它在以下情况下关闭(!completed | | content.length==0)