【问题标题】:Angular 7 - PrimeNg ConfirmationDialog problemAngular 7 - PrimeNg ConfirmationDialog 问题
【发布时间】:2020-09-24 02:32:53
【问题描述】:

我有一个使用PrimeNg 组件的Angular 应用程序。我对ConfirmDialogModule 有疑问。

这是我的html

  <p-table [columns]="tableCols" [value]="currentEstablishment.Sales" [rows]="10" [paginator]="true">
       <ng-template pTemplate="header" let-columns class="cervezapp-grid-header-column">
           <tr class="cervezapp-grid-header-row">
               <th *ngFor="let col of columns" [ngClass]="col.field == 'Date' ? 'col-header-date' : col.field == 'Detail' ? 'col-header-detail' : col.field =='Price' ? 'col-header-price' : col.field == 'SeeDet' ? 'col-header-seedet' : 'col-header-actions'">
                    <div [ngClass]="col.field == 'Date' ? 'col-header-date' : col.field == 'Detail' ? 'col-header-detail' : col.field =='Price' ? 'col-header-price' : col.field == 'SeeDet' ? 'col-header-seedet' : 'col-header-actions'">
                        {{col.header}}
                        </div>
                    </th>
                </tr>
            </ng-template>
            <ng-template pTemplate="body" let-sale let-columns="columns">
                <tr class="table-body-row">
                    <td *ngFor="let col of columns">
                        <span *ngIf="col.header == 'Fecha'">{{sale[col.field]}}</span>
                        <span *ngIf="col.header == 'Detalle de venta'" class="table-body-col-small">{{sale[col.field]}}</span>
                        <span *ngIf="col.header == 'Precio total'" class="table-body-col-small">$ {{sale[col.field]}}</span>
                        <span *ngIf="col.header == 'Ver Detalle'" class="table-body-col-small">
                            <img src="../../../assets/icons/Details.svg" class="delete-icon" (click)= "show()">
                        </span>
                        <span *ngIf="col.header == 'Acciones'" class="table-body-col-small">
                            <img src="../../../assets/icons/Delete.svg" class="delete-icon" (click)="openDeleteSaleModal(sale.Id)">
                            <img src="../../../assets/icons/Edit.svg" class="edit-icon">
                        </span>
                    </td>
                </tr>
           <p-confirmDialog ></p-confirmDialog>
      </ng-template>
  </p-table>

这是我的.ts 文件中的openDeleteSaleModal 方法:

openDeleteSaleModal(Id: number){
    console.log("delete sale");
    this.confirmationService.confirm({
      message: 'Esta seguro que desea eliminar esta venta?',
      header: 'Eliminar Venta',
      icon: 'fa fa-question-circle',
      accept: () => {
        console.log("Worked");
      },
      reject: () => {
        console.log("Test");
      }
    })
  }

我的app.module文件终于来了

import {DynamicDialogModule} from 'primeng/dynamicdialog';


imports: [
    DynamicDialogModule
  ],

在控制台日志上,我只看到它执行了一次,但模态显示如下:

屏幕变黑是因为打开了大约 10 个模态实例。我必须按 10 次取消按钮,这样确认对话框才开始关闭,屏幕再次出现。

关于这里可能出现什么问题的任何想法?

【问题讨论】:

  • 您正在表体创建对话框实例,因此如果您的表上有 500 行,则对话框打开 500 次。

标签: typescript angular7 primeng angular-module


【解决方案1】:

我自己想通了,问题出在

<p-confirmDialog ></p-confirmDialog>

标签位置,应该在

之外
<p-table>
</p-table>

我有 10 行的分页,模式打开了 10 次,把

<p-confirmDialog ></p-confirmDialog>

table之外的问题解决了

希望对未来的人有所帮助

【讨论】:

  • 非常感谢!!我遇到了完全相同的问题,我有 10 行的分页,确认对话框打开了 10 次。在我阅读您的回答之前无法弄清楚为什么会发生这种情况:)非常感谢:)
猜你喜欢
  • 2018-04-16
  • 2018-12-19
  • 2021-10-11
  • 2018-06-02
  • 2017-01-20
  • 1970-01-01
  • 2019-09-11
  • 2021-12-27
  • 1970-01-01
相关资源
最近更新 更多