簡體   English   中英

在Angular中的對象內部訪問數組中的對象

[英]Accessing objects in arrays inside objects in Angular

我很難通過api調用訪問數據並將其顯示在Mapbox上。 我可以在地圖上顯示一個標記,而我應該有10個標記。 我認為ng-repeat做錯了,但我不確定是什么。 任何幫助,將不勝感激。

這是一個鏈接,用於查看來自API調用的完整JSON響應http://jsonblob.com/55e734cee4b01190df374f1e

// index.html
  <div ng-repeat="venue in bars.venues">
    <marker lat="{{venue.location.lat}}" lng="{{venue.location.lng}}">
      <h1>{{venue.name}}</h1>
      <p>{{venue.contact}}</p>
      <p>{{venue.location.formattedAddress}}</p>
    </marker>
  </div>

// app.js
    $http.get(url)
      .then(function (response) {
        $scope.bars = response.data.response;
    });

// sample data from api
{
  "meta": {
    "code": 200,
    "requestId": "55e72707498e3d9a002d7bc4"
  },
  "response": {
    "venues": [
      {
        "id": "42c1e480f964a520c4251fe3",
        "name": "The View",
        "contact": {
          "phone": "4158961600",
          "formattedPhone": "(415) 896-1600"
        },
        "location": {
          "address": "55 4th St",
          "crossStreet": "at Marriott Marquis",
          "lat": 37.78510950100554,
          "lng": -122.40469515323639,
          "distance": 29,
          "postalCode": "94103",
          "cc": "US",
          "city": "San Francisco",
          "state": "CA",
          "country": "United States",
          "formattedAddress": [
            "55 4th St (at Marriott Marquis)",
            "San Francisco, CA 94103",
            "United States"
          ]
        },
        "categories": [
          {
            "id": "4bf58dd8d48988d1d5941735",
            "name": "Hotel Bar",
            "pluralName": "Hotel Bars",
            "shortName": "Hotel Bar",
            "icon": {
              "prefix": "https://ss3.4sqi.net/img/categories_v2/travel/hotel_bar_",
              "suffix": ".png"
            },
            "primary": true
          }
        ],
        "verified": false,
        "stats": {
          "checkinsCount": 12634,
          "usersCount": 9499,
          "tipCount": 121
        },
        "url": "http://www.sfviewlounge.com",
        "hasMenu": true,
        "menu": {
          "type": "Menu",
          "label": "Menu",
          "anchor": "View Menu",
          "url": "https://foursquare.com/v/the-view/42c1e480f964a520c4251fe3/menu",
          "mobileUrl": "https://foursquare.com/v/42c1e480f964a520c4251fe3/device_menu"
        },

所以我弄清楚了為什么只顯示一個標記。 我以前使用的是谷歌角度地圖,並將ngMaps作為模塊。 刪除后,所有標記均顯示。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM