Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/asp.net/37.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Angularjs 数组长度等于零后自动关闭uibModal_Angularjs_Modal Dialog_Angular Ui Bootstrap_Servicenow - Fatal编程技术网

Angularjs 数组长度等于零后自动关闭uibModal

Angularjs 数组长度等于零后自动关闭uibModal,angularjs,modal-dialog,angular-ui-bootstrap,servicenow,Angularjs,Modal Dialog,Angular Ui Bootstrap,Servicenow,我们的团队正在ServiceNow中开发一个附件小部件。该小部件允许用户附加文档、查看文档以及根据需要删除文档。为了查看附件,我们通过uibModal利用模式窗口。如果用户删除了所有附件,并且数组长度达到零,我们希望模式窗口自动关闭,但我们似乎无法使其正常工作 <label> <sp-attachment-button></sp-attachment-button> </label> <span ng-if="attachments.l

我们的团队正在ServiceNow中开发一个附件小部件。该小部件允许用户附加文档、查看文档以及根据需要删除文档。为了查看附件,我们通过uibModal利用模式窗口。如果用户删除了所有附件,并且数组长度达到零,我们希望模式窗口自动关闭,但我们似乎无法使其正常工作

<label>
  <sp-attachment-button></sp-attachment-button>
</label>

<span ng-if="attachments.length>0" class="badge" ng-click="c.openModal()">{{attachments.length}}</span>

<script type="text/ng-template" id="modalTemplate">
 <div class="panel panel-default">
   <div class="panel-heading flex">
     <h4 class="panel-title">Attachments</h4>
     <i type="button" class="fa fa-times" style="margin-left:auto;" ng-click="c.closeModal()"></i>
   </div>
   <div class="panel-body">
     <now-attachments-list template="sp_attachment_single_line"></now-attachments-list>
   </div>
   <!--<div class="panel-footer text-right">
     <button class="btn btn-primary" ng-click="c.closeModal()">${Close Modal}</button>
   </div>-->
 </div>
</script>

关于如何让模态自动关闭,有什么建议吗?

我们找到了答案。我们必须观察阵列,然后在阵列归零后关闭模态:

$scope.$watch(function () {  
    return $scope.attachments;
}, function (value) {  
    if(value.length==0){
        if(c.modalInstance){
            c.modalInstance.close();
        }
    }
});  

您是否尝试使用$uibModalInstance.close()来关闭它?
$scope.$watch(function () {  
    return $scope.attachments;
}, function (value) {  
    if(value.length==0){
        if(c.modalInstance){
            c.modalInstance.close();
        }
    }
});