简体   繁体   English

在Angular中的对象内部访问数组中的对象

[英]Accessing objects in arrays inside objects in Angular

I am having quite a hard time accessing data from an api call and having it shown on Mapbox. 我很难通过api调用访问数据并将其显示在Mapbox上。 I am able to have one marker shown on the map, while I should have 10 markers. 我可以在地图上显示一个标记,而我应该有10个标记。 I think I am doing something wrong with ng-repeat, but I am not sure what. 我认为ng-repeat做错了,但我不确定是什么。 Any help would be appreciated. 任何帮助,将不胜感激。

Here is a link to view the full JSON response from the API call http://jsonblob.com/55e734cee4b01190df374f1e 这是一个链接,用于查看来自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"
        },

So I figured out why only one marker was showing. 所以我弄清楚了为什么只显示一个标记。 I was previously using angular google maps and had ngMaps as a module. 我以前使用的是谷歌角度地图,并将ngMaps作为模块。 After I deleted it, all my markers showed. 删除后,所有标记均显示。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM