我的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">×</span>
</button>
</div>
<div class="modal-body">
<p>Test Hardware 1, sätt behörighet…</p>
<p>Test Hardware 2…</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>
答案 0 :(得分:0)
如果您使用的是MatDialog ===&gt; 使用这种方式将数据传递给模态 的 abcComponent.ts 强> ==&GT;
const dialogRef = this.dialog.open(MyModalComponent, {
data: { Content:this.content, LatTmp:this.latTmp }
});
现在在 MyModalComponent.ts ==&gt;
中接收该数据 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)
}