0

我的 Angular5 应用程序中有一个 component.hmtl,它有一个名为 markerClick 的函数,可以打开一个模式。在模态中,我想显示我在 markerClick 函数中发送的 item.lat 参数,但无法做到这一点,需要您的帮助。

首先是component.ts 代码,然后是下面的component.html 代码。

open(content, latTmp) {
  this.modalService.open(content, latTmp).result.then((result) => {
    this.closeResult = `Closed with: ${result}`;
  }, (reason) => {
    this.closeResult = `Dismissed ${this.getDismissReason(reason)}`;
  });
  console.log(latTmp);
}
<div style="text-align:center">
  <h1>
    Welcome to {{ title }}!
  </h1>


  <agm-map [latitude]=57.107118 [longitude]=12.2520907 [zoom]="4">

    <ng-container *ngFor="let item of station">
      <agm-marker [latitude]="item.Lat" [longitude]="item.Lng" (markerClick)="open(content, item.Lat)">
      </agm-marker>
    </ng-container>

  </agm-map>
  <!-- </ng-container> -->
  <!-- <img width="100%" height="400" alt="World Map" src="assets\images\SyntronicWorldMap.gif"> -->
</div>





<ng-template #content let-c="close" let-d="dismiss">
  <div class="modal-header">
    <h4 class="modal-title">Station Info</h4>
    <button type="button" class="close" aria-label="Close" (click)="d('Cross click')">
      <span aria-hidden="true">&times;</span>
    </button>
  </div>
  <div class="modal-body">
    <p>Test Hardware 1, sätt behörighet&hellip;</p>
    <p>Test Hardware 2&hellip;</p>
    **HERE I WANT TO DISPLAY ITEM.LAT PARAMETER SENT FROM THE MARKERCLICK FUNCTION!!!!!**

  </div>
  <div class="modal-footer">
    <button type="button" class="btn btn-outline-dark" (click)="c('Close click')">Close</button>
  </div>
</ng-template>

4

1 回答 1

1

如果您使用 MatDialog ==> 使用这种方式将数据传递给模态 **abcComponent.ts ==>

   const dialogRef = this.dialog.open(MyModalComponent, {
      data: { Content:this.content, LatTmp:this.latTmp }
   });

现在在 **MyModalComponent.ts ==> 中接收该数据

  constructor(
    public dialogRef: MatDialogRef<MyModalComponent>,
    @Inject(MAT_DIALOG_DATA) public data: any  ) { }

  ngOnInit(){
     var receiveContent = this.data.Content;
     var receiveLatTmp = this.data.latTmp;
     console.log(receiveContent,receiveLatTmp)
  }
于 2018-05-14T14:10:33.217 回答