加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > 安全 > 正文

angular – agm标记不能从ngfor渲染

发布时间:2020-12-17 10:16:23 所属栏目:安全 来源:网络整理
导读:我对角度很新,我认为这是一个基本问题. 我创建我的地图 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
我对角度很新,我认为这是一个基本问题.

我创建我的地图

<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>

当我手动设置标记时,一切正常,但是当我使用* 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();
}

}

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

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

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

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读