角度模态未关闭($ uibModal)

时间:2016-02-03 12:37:05

标签: jquery angularjs modal-dialog bootstrap-modal ui.bootstrap

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)

感谢您的时间。

2 个答案:

答案 0 :(得分:5)

modalInstance.close()控制器

中使用UserModalCtrl
app.controller('UserModalCtrl', ['$scope', '$modalInstance' function($scope ,modalInstance {
  $scope.close = function () {
   modalInstance.close();
  };
}]);

答案 1 :(得分:0)

我认为我做过类似的事情。

我有一个$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,你关闭了模态。

相关问题