【发布时间】:2018-08-12 13:48:26
【问题描述】:
你好,有人可以向我解释一下如何使它正常工作,因为我在使用 viewChild 指令方面不是很有经验...
这就是交易,我正在开发一个有角度的小型 crud 应用程序,并有一个包含我的数据的填充表,在每一行我都有一个删除按钮,它打开一个小的确认窗口,我已经设法获得模态(ngx-bootstrap 3)点击打开,现在我必须弄清楚如何从我的父组件调用函数,我的http请求与我表上的按钮一起工作,但当我尝试修改它以打开模式并制作单击确认按钮的删除请求...
这是一些代码,在我的父 app.component.html 小表中...
<table style="width:100%" class="table table-striped"
id="billing_history_table">
<thead class="head">
<tr>
<th>Name</th>
<th></th>
</tr>
</thead>
<tbody>
<tr *ngFor="let e of employeelist>
<td>{{e.firstName}}</td>
<td><a (click)="childModal.show()"><span class="glyphicon
glyphicon-trash"></span></a></td>
</tr>
</tbody>
</table>
<app-modal-component #childModal>
</app-modal-component>
在我的父组件 app.component.ts 中
@ViewChild('childModal') childModal: ModalComponent;
这是我想在打开的模式中调用的函数,来自父组件。
DeleteEmployee(id: string) {
this._usermanagementservice.deleteEmployee(id).subscribe(res => {
this.LoadAllEmployees();
})
}
Id 来自我的数据库,未在表格中显示,我不知道如何将其传递给 modal
在子组件中我有
@ViewChild('childModal') public childModal: ModalDirective;
show() {
this.childModal.show();
}
hide() {
this.childModal.hide();
}
在子组件.html中
<div bsModal #childModal="bs-modal" class="modal fade" tabindex="-1"
role="dialog" [config]="{backdrop: 'static'}" aria-hidden="true">
<div class="modal-dialog modal-sm">
<div class="modal-content">
<div class="modal-body text-center">
<p>Do you want to confirm?</p>
<button type="button" class="btn btn-default"
(click)="confirm()">Yes</button>
<button type="button" class="btn btn-primary"
(click)="hide()">No</button>
</div>
</div>
</div>
</div>
希望您理解我的问题,子 .html 中的确认按钮应该触发 DeleteEmployee 函数并使用我表中的 Id 发出删除请求... 我知道它必须对输出和事件发射器做一些事情,但我不知道,谢谢:(
【问题讨论】:
标签: angular modal-dialog ngx-bootstrap viewchild