首页 > 解决方案 > 什么是 TypeScript 中用于读取/获取数据的 *NgFor

问题描述

当我单击按钮时,我尝试在 TypeScript 中获取/显示数据。但我只能显示一次数据。我开始了,我不明白所有的事情。(对不起我的英语)

我已经尝试过使用 forEach,但只能使用一次。

   async spotAdded() {
    this.spots = this.spotService.getSpots(); // i get my data from here
    this.spots.forEach(info => {
      info.forEach(infos => {
        console.log(infos);
        const marker: Marker = this.map.addMarkerSync({
        position: {
          lat: infos.lat,
         lng: infos.lng
          },
        title: infos.description,
        snippet: infos.user,
        disableAutoPan: true
        });
        marker.showInfoWindow();
        });
    });
}    

我实际上有这个,但对于数据库中的每个点只有一次(我使用 firebase):

{id:“NbtJraND8XhSDUG8rlRY”,createdAt:1559308376871,描述:“Quatre”,flat:false,lat:48.996672,...}

标签: javascripthtmltypescript

解决方案


推荐阅读