0

我正在尝试在单击角度表中的一系列时启动 ngx-modaltr并传递 ngx-modal 必须使用的数据。对于每个 cicked tr,模态必须传入不同的值。

这是启动模式的“主”.ts 组件中的方法:

  openModal(dummyItem) {
    const initialState = {
      clientId: dummyItem.clientId,
      clientName: dummyItem.clientName,
      facType: dummyItem.type,
      localCode: dummyItem.localCode,
      from: dummyItem.from,
      to: dummyItem.to,
      localName: dummyItem.localName,
      class: "modal-lg"
    };
    this.bsModalRef = this.modalService.show(DetalleFacturaPopUpComponent, {
      initialState,
      backdrop: "static",
      keyboard: false
    });
  }

在主模板中,方法“openModal(dummyItem)”tr作为click事件使用 a附加到每一个*ngFor,因此对于每一行,模式都使用传入的不同数据启动,这样:

<tr *ngFor="let dummyItem of facturas" (click)="openDetalleFacturaAmpliado(dummyItem)" >
   <td>{{ dummyItem.numFac }}</td>
   <td class="text-center">{{ dummyItem.clientId}}</td>
   <td class="text-center">{{ dummyItem.clientName}}</td>
   <td class="text-center">{{ dummyItem.localCode}}</td>
   <td class="text-center">{{ dummyItem.localName}}</td>
   <td class="text-center">{{ dummyItem.from}}</td>
   <td class="text-center">{{ dummyItem.to}}</td>
   <td class="text-center">{{ dummyItem.type}}</td>
</tr>

问题是我不知道如何在模态 .ts 文件中获取这些数据。

以下代码来自“DetlleFacturaPopUpComponent.ts”,它是从第一个启动的组件:

export class DetalleFacturaPopUpComponent implements OnInit {

  ngOnInit() {
    console.log(initialState.clientId)
}

但当然,这失败了。“initialState”属性根本无法识别。我将它填充在主要的 .ts 中,但我无法弄清楚如何抓取和使用它。

我希望能够用传递给模态组件的变量“initialState”的属性值填充表单(模态的模板是一个表单),但我无法做到它......如果我至少可以控制台记录其中一个值,我可以制作我正在尝试开发的应用程序的其余部分。

您能帮我弄清楚如何使用传递给 ngx-modal 的数据吗?谢谢。

4

0 回答 0