我使用角度4和agm地图标记我创建标记使它无法正常工作, 我已经把下面的代码请电话给任何一个如何解决它。
import { Component, OnInit } from '@angular/core'; import { IDashItem } from '../../../Interface/dashitem'; import { DashService } from '../../../services/dash.service' @Component({ selector: 'app-slider', templateUrl: './slider.component.html', styleUrls: ['./slider.component.css'] }) //export class SliderComponent implements OnInit { lat: number = -43.9509; lng: number = -34.4618; zoom: number = 4; //httpdata: any; constructor(private dashservice: DashService) { } ngOnInit() { return this.dashservice.getdashitem().subscribe(Response => { this.httpdata = Response; console.log(this.httpdata) }) } } interface marker{ name?: string; lat?: number; lng?: number; draggable?: boolean; }
map.components.html
<!-- Heading Row -->
<div class="row my-4">
<div class="col-lg-8">
<agm-map [latitude]="lat" [longitude]="lng" [zoom]="zoom" [zoomControl]="false" (mapClick)="mapClicked($event)">
<agm-marker
*ngFor ="let map of httpdata; let i = index"
(markerClick)="clickedMarker(map, i)"
[latitude]="map.address.geo.lat"
[longitude]="map.address.geo.lng">
</agm-marker>
</agm-map>
</div>
<!-- /.col-lg-8 -->
<div class="col-lg-4">
<app-bn-tagline></app-bn-tagline>
<div *ngFor ="let map of httpdata; let i = index">
<label>{{map.address.geo.lat}}</label>
<label>{{map.address.geo.lng}}</label>
</div>
</div>
<!-- /.col-md-4 -->
</div>
<!-- /.row -->
答案 0 :(得分:0)
FilteredResults.java
变量正在异步解析。您是否可以尝试在map.components.html中更改此行:
imageAdapter = new ImageAdapter(listOfNames);
具有:
httpdata
答案 1 :(得分:0)
我也面临着同样的问题,因此尝试了@ user1183098给出的上述答案,但对我而言不起作用。所以我用下面的概念解决了这个问题:
Here the problem is due to async data coming from services.So you can do something like store the data coming from services first in some variable (let say httpData) then after the completion of that method, trigger a function which will return the data saved in the variable httpData.
现在,在上述给定的角度代码中将httpdata
替换为httpData
。