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');
我无法在用户添加完成后关闭模型。在用户模式上,我显示进度条。代码运行良好,没有错误,但模式保持打开状态。我也尝试了$uibModalInstance但控制器抛出错误:未知提供程序(无法在同一 UserCtrl 上注入$uibModalInstance)我正在注入 ui.bootstrap (ui-bootstrap-tpls-1.1.2.js)
谢谢你的时间。
在UserModalCtrl
控制器中使用modalInstance.close()
app.controller('UserModalCtrl', ['$scope', '$modalInstance' function($scope ,modalInstance {
$scope.close = function () {
modalInstance.close();
};
}]);
我也做过类似的事情。
我有一个看起来像这样的$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
}
});
});
注入的loading
是如下所示的服务
myApp.factory('loading', function() {
return {
status: ''
}
});
当我将加载服务的状态更改为"成功"(从任何地方,而不是模态控制器)时,模态将关闭。
我不知道这是否正是您的要求,但我希望它有所帮助,如果有什么不清楚的地方,请问!
编辑:因此,假设您有一个值为isCompleted: false
的服务,将该服务注入您的模态控制器,并使用$watch
函数,然后当该isCompleted
更改为true
时,您关闭模态。