Angular JS:隐藏/关闭模态

Angular JS :Hide/Close a Modal

本文关键字:模态 隐藏 JS Angular      更新时间:2023-09-26

在Angular JS 中关闭模态时遇到问题

HTML

   <div class="container">
        <div class="col-md-12" id="gridSet">
            <div class="gridStyle adjustViewPort" ng-grid="gridOptions"></div>
            // Here is the HTML template for MODAL.
            <script type="text/ng-template" id="myModalContent.html">
                <div class="modal-body">
                <p>No Events Found</p>
                <p><button class="btn btn-primary"  ng-click="myClickEvent()">OK</button></p>
                </div>
            </script>
        </div>
  </div>

controller.js中看起来像

$scope.modalInstance=$modal.open({templateUrl: 'myModalContent.html'});
//This should run. But, every time only Cancelled is logged.
$scope.modalInstance.result.then(function() {
                    console.log('Success'); // This is never executed.
                    }, function() {
                    console.log('Cancelled');
                    })['finally'](function(){
                    $scope.modalInstance = undefined  
                    });

我试图在myClickEvent中隐藏this.$hide();的模态,但是,根本没有调用该函数。

来自Plunker的代码,我从中复制了代码。

查找1)使用$timeout在几秒钟后隐藏模态2) 当用户选择OK时关闭模式。

更新

问题是Plunker中的代码将$modalInstance显示为依赖项,我无法注入。

函数'ng-click="myClickEvent()"'调用控制器中的一个函数,如下所示。

$scope.myClickEvent=function(){
     alert('the function is called.');
}

但是,没有警报。

感谢您提前提供帮助。

使用close()方法:

 $scope.close = function () {
        $modalInstance.close();
    };
<button class="btn btn-warning" ng-click="close()">Close</button>