angular - 在 Angular 6 中调用不同的 ng-bootstrap 模式弹出窗口
问题描述
我正在按照 ng-bootstrap 模态弹出窗口的教程在网格中添加、编辑和删除。我使用以下按钮将 ng-template 添加到 Add
<button type="button" class="btn btn-primary" (click)="openAdd(content)" >Add</button>
这将打开一个带有以下 ng-template 代码的模式对话框
<ng-template #content let-modal>
<div class="modal-header">
<h4 class="modal-title" id="modal-basic-title">{{meetingDateTitle}}</h4>
<button type="button" class="close" aria-label="Close" (click)="modal.dismiss('Cross click')">
<span aria-hidden="true">×</span>
</button>
</div>
<div class="modal-body">
<form>
<div class="form-group">
<label for="meetingDate">Meeting Date:</label>
<div class="input-group">
<input id="meetingDate" class="form-control" placeholder="yyyy-mm-dd" name="dp1" #c2="ngModel" [(ngModel)]="meetingRequest.MeetingDt" ngbDatepicker #d1="ngbDatepicker">
<div class="input-group-addon" (click)="d1.toggle()" >
<span class="glyphicon glyphicon-calendar" aria-hidden="true"></span>
</div>
</div>
<br/>
<br/>
</div>
</div>
</form>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-outline-dark" (click)="modal.close('Close click')">Close</button>
<!-- <button type="button" class="btn btn-outline-dark" (click)="saveAddMeeting">Save</button> -->
<input type="submit" value="Save" class="btn btn-primary" (click) ="saveMeeting()" >
</div>
</ng-template>
我的问题,如果我为删除确认创建另一个 ng-template,我如何调用不同的弹出对话框窗口?
I see that the bootstrap call for another button is this.modalService.open(content, { centered: true});
用于调用 Add 弹出窗口。如何进行另一个 modalService.open 调用来调用删除对话框。
谢谢
解决方案
只需将content
您传入的参数更改为您的函数。此变量在模板范围内声明#content
并代表您的ng-template
元素。
<button type="button" class="btn btn-primary" (click)="openAdd(content)" >Add</button>
<button type="button" class="btn btn-primary" (click)="openAdd(delete)" >Delete</button>
<ng-template #content let-modal>
...
</ng-template>
<ng-template #delete let-modal>
...
</ng-template>
推荐阅读
- python - 如何打印包含某些特定模式的程序的完整功能摘录
- crashlytics-android - Crashlytics 缺少带有 android 应用程序包的 NDK 符号
- c# - 如何同时运行具有不同返回类型的两个任务列表
- networking - HTTP 1.x 缺少什么来允许像 HTTP 2 这样的多路复用
- vim - 如何让 vim bang 命令找到我的函数
- typescript - 解析数组
使用某些匹配器更新对象数组中的字段后 - python - 在折线图中绘制来自 pandas 数据框的数据
- objective-c - 当我收到通知时,有没有办法获取当前位置?
- javascript - ng-if 在异步调用期间显示两个元素
- java - 错误:类 org.hibernate.ejb.HibernatePersistence 具有接口 org.hibernate.ejb.AvailableSettings 作为超类