不能从ngfor渲染的agm标记

use*_*108 8 angular-google-maps ngfor angular

我对角度很新,我认为这是一个基本问题.

我创建我的地图

<agm-map [latitude]="lat" [longitude]="lng">
    <agm-marker [latitude]="location.lat" [longitude]="location.lng" *ngFor="let location of locations; let i=index">
        <agm-snazzy-info-window [maxWidth]="200" [closeWhenOthersOpen]="true">
            <ng-template>
                <strong>{{location.title}}</strong>
                <p>adresse</p>
            </ng-template>
        </agm-snazzy-info-window>
    </agm-marker>
</agm-map>
Run Code Online (Sandbox Code Playgroud)

当我手动设置标记时,一切正常,但是当我*ngFor用来遍历我的列表时,会创建标记的html,但显然在地图的脚本查找标记之后,所以没有标记被渲染(地图本身就是) .

从我的控制器:

export class LocationMapComponent implements OnInit {

 lat: number = 51.678418;
 lng: number = 7.809007;
 locations: Location[];

 async ngOnInit() {

}

public async getLocations()  {
    this.locations = await this._locationService.getLocations();

}

constructor(private _locationService:LocationService, private _coreCOMService: CoreCOMService, private _coreLanguageService: CoreLanguageService, private _coreLogService: CoreLogService, private _componentFactoryResolver: ComponentFactoryResolver, private _coreSystemService: CoreSystemService) {

    this.getLocations();
}
Run Code Online (Sandbox Code Playgroud)

}

这些位置是从一个从远程数据库中获取它们的服务加载的.我确实认为问题是在执行ngFor循环之前渲染了地图,我不确定如何确保首先执行循环或者如何告诉地图仅在循环之后(重新)渲染标记已经完成了.

如上所述,这可能是非常基本的,但我现在感到茫然,谢谢.

Dal*_*ale 12

纬度/经度必须是数字类型.如果它们作为字符串从API或某种服务返回,则需要转换它们.根据我的经验,它似乎要求严格键入数字.