操作成功后关闭角度弹出模型对话框

时间:2019-08-05 08:26:02

标签: angular

这是我的模型Pop Up的角度代码,

<form #addNewItem="ngForm" (ngSubmit)="onNewItemCreate(addNewItem.form.valid)">
        <div class="modal" id="addNewItem" role="dialog"  ng-show="addNewModelShow">
          <div class="modal-dialog modal-dialog-centered">
            <div class="modal-content">
              <div class="modal-header">
                <h4 class="modal-title">Add New Item</h4>
                <button type="button" class="close" data-dismiss="modal">&times;</button>
              </div>
              <div class="modal-body">
              .......
              .......

这就是我显示此弹出窗口的方式,

<a class="dropdown-item add-link" data-toggle="modal" data-target="#addNewItem">

我在Typescript上具有项创建功能,在我的函数中,当Item插入成功时,我想关闭弹出式模型(来自Typescript)

onNewItemCreate(isValid: boolean) {
......
......
    if(itemCreatedSuccess) {
        // I want to close pop up here
    } else {
        ....
    }
}
  

我已经尝试过addNewModelShow = false,但没有用。

2 个答案:

答案 0 :(得分:0)

看起来您正在使用Bootstrap,对吧?

如果是这样,您可以像这样调用hide例程:

$('#addNewItem').modal('hide')

查看Bootstrap模态here的完整文档。

答案 1 :(得分:0)

如果您希望从控制器端关闭模式,则可以使用这种方式

$("#addNewItem").modal("hide");