0

I've this JSON:

{
  "success": true,
  "return": {
    "totalItem": 7,
    "totalPages": 1,
    "pageSize": 7,
    "items": {
      "phones": [
        "(48) 9999-9999"
      ],
      "users": {
        "manager": {
          "id_user": "5819",
          "name": "Síndico Ilhas Belas",
          "user": "sindico.teste@domain.com",
          "photo": "https://domain.amazonaws.com/files/upload/2015/07/25/5819.55b32d90e69ab3.05638898_873f970f8d259.jpg"
        },
        "employees": [
          {
            "id_user": "2",
            "name": "José Perez",
            "user": "pepe@domain.com",
            "photo": "https://.amazonaws.com/files/upload/2013/10/07/2.52523a0451c3c5.59697102_7a4188d3.jpg",
            "groups": [
              {
                "id_group": "33",
                "name": "Portaria"
              }
            ],
            "work_details": {
              "work_schedule": "8-12hs e 14-18hs",
              "work_activities": "Supervisionar os trabalhos de conservação"
            }
          },
          {
            "id_user": "15142",
            "name": "Marcos Rojas",
            "user": "rojas@c.com",
            "photo": "http://www.domain.com/themes/intra/img/sf_ele.gif",
            "groups": [
              {
                "id_group": "589",
                "name": "Zeladoria"
              }
            ],
            "work_details": {
              "work_schedule": "8h 12h",
              "work_activities": "Zeladoria"
            }
          },
          {
            "id_user": "18833",
            "name": "Portaria",
            "user": "teste@domain.com",
            "photo": "http://www.domain.com/themes/intra/img/sf_ele.gif",
            "groups": [
              {
                "id_group": "33",
                "name": "Portaria"
              }
            ],
            "work_details": {
              "work_schedule": "8hs por dia. 8-12hs e 14-18hs",
              "work_activities": "Supervisionar os trabalhos de conservação"
            }
          }
        ],
        "boardMembers": [
          {
            "id_user": "8189",
            "name": "Ana Maria",
            "user": "8189",
            "photo": "http://www.domain.com/themes/intra/img/sf_ela.gif",
            "groups": [
              {
                "id_group": "722",
                "name": "Subsíndico"
              }
            ]
          },
          {
            "id_user": "11442",
            "name": "Luciana Zath",
            "user": "lzath@mail.com",
            "photo": "http://www.domain.com/themes/intra/img/sf_ela.gif",
            "groups": [
              {
                "id_group": "1456",
                "name": "Conselho fiscal"
              }
            ]
          }
        ]
      }
    }
  }
}

Because manager is only one record, i can't get it with ng-repeat in this code

<div class="card" ng-repeat="(manager, name) in items">
    <pre>{{name}}</pre>
</div>

JSON returns all data, but i need return only manager data, for example:

Name, User (email) and photo

And controller:

// Controller of about.
appControllers.controller('aboutCtrl', function($scope, $mdBottomSheet, $mdToast, $mdDialog, About) {

    About.get(function(data) {
        $scope.items = data.return.items;
        console.log(data);
    })

}); // End of about controller.

employees and boardMembers works fine with ng-repeat, but single record for manager, not

Carlos
  • 28
  • 5

4 Answers4

0

If manager is always a single object just do:

 Manager: {{items.users.manager.name}}

Then repeat over the employees array

 <div ng-repeat="employee in items.users.employees">
    Employee:  {{employee.name}}
charlietfl
  • 170,828
  • 13
  • 121
  • 150
0
appControllers.controller('aboutCtrl', function($scope, $mdBottomSheet, $mdToast,
    $mdDialog, About) {

    About.get(function(data) {
        $scope.items = data.return.items;
        $scope.manager = data.return.items.users.manager;       
        console.log(data);
    })
}); // End of about controller.

in html:

 <p>{{manager.name}}</p>
 <p>{{manager.user}}</p>
zekel
  • 9,227
  • 10
  • 65
  • 96
Ashkan Hovold
  • 898
  • 2
  • 13
  • 28
0

You can only iterate through a list of items using ng-repeat if items are an array. In your JSON, items are an object, so you will not get manager name. Just use {{items.users.manager.name}} to get manager name. On the other hand you could use ng-repeat to iterate over items.users.employees, because it's employees property is an array.

<div class="card" ng-repeat="employee in items.users.employees">
    <pre>{{employee.name}}</pre>
</div>
codeepic
  • 3,723
  • 7
  • 36
  • 57
-2

You can access it with

{{items.users.manager}}
luk492
  • 350
  • 3
  • 15