我创建了一个引导程序 NgModal。在表中,单击编辑按钮后,它包含一个带有一些输入字段的表单。如果我点击保存它工作正常但如果我点击取消它正在关闭但它也在更新字段数据。我想如果我点击取消它不应该保存数据或更新数据。
app.component.ts
> import { NgbModalConfig, NgbModal, NgbModalOptions} from '@ng-bootstrap/ng-bootstrap';
> .....
> constructor(private config: NgbModalConfig,
> private modalService: NgbModal)
> {
> config.backdrop = 'static';
> config.keyboard = false;
> }
> .....
> editCharges(event:any, content, aRow, rowIndex){
> console.log("content of charges: ",content);
> console.log("aRow: ",aRow);
> console.log("rowIndex: ",rowIndex);
> this.chargesDetail = aRow;
> this.chargesDetail.rowIndex = rowIndex;
> this.overrideCharges = false;
> event.target.closest('datatable-body-cell').blur();
> this.modalService.open(content,{size: 'lg', windowClass: 'modal-xl'}).result.then((result) => {
> console.log("closed ", result);
> }, (reason) => {
> console.log("Charges.dismissed " , reason);
> });
> }
......
app.component.html
<ngx-datatable-column name="Actions">
<ng-template ngx-datatable-cell-template let-row="row" let-rowIndex="rowIndex">
<a *ngIf="loggedInUser.userType !== 'RECEIVER'" class="success p-0" data-original-title="" title="Edit" (click)="editGoods($event, goodsContent,row, rowIndex)">
<i class="ft-edit-2 font-large-1 mr-2"></i>
</a>
....
<ng-template #chargesContent let-c="close" let-d="dismiss">
<div class="modal-footer">
<button type="button" [disabled]="!chargesForm.valid" style="margin-right: 6px;" class="btn btn-raised btn-primary"
(click)="saveCharges(chargesForm);c('data saved')">
<i class="fa fa-check-square-o"></i> Save
</button>
<button type="button" class="btn btn-raised btn-warning mr-1" data-dismiss='modal' (click)="d('cancel click')">
<i class="ft-x"></i> Cancel
</button>
</div>
</ng-template>