0

I have this type of json object:

[
    {
        "contactsCount": 2,
        "id": 1,
        "userKey": "$2a$10$3jCL8.rJV9/KS11MtrB4r.0uE4Fu/rGwEk.ko0HTkzFNiKXhh1.X.",
        "groupname": "Angular",
        "createdAt": "2018-01-15T07:21:42.000Z",
        "updatedAt": "2018-01-15T07:21:42.000Z",
        "contactgroups": [
            {
                "id": 1,
                "contact": {
                    "id": 1,
                    "gsm": "111111111",
                    "firstname": "Mohamed",
                    "lastname": "Sameer"
                }
            },
            {
                "id": 3,
                "contact": {
                    "id": 3,
                    "gsm": "222222222",
                    "firstname": "Rizwan",
                    "lastname": "Riz"
                }
            }
        ]
    }
]

I am getting this in $scope.modalData.

I have to show my gsm, first name and last name in table:

My jade code:

table.table
tr
 th GSM
 th First Name
 th Last Name

tr(ng-repeat='testData in modalData.contactgroups[0]')
 td {{testData.gsm}} 
 td {{testData.firstname}}
 td {{testData.lastname}}

anyone help me, i am not getting data, can anyone explain me how to do that?

I am getting this response when user click edit button from another table:

$scope.modalData = {};
    $scope.setModal = function (data) {
        $scope.modalData = data;
        console.log($scope.modalData);
    }




Jade:
    td
      a(data-toggle='modal',ng-click='setModal(groups[$index])' ) Groups
5
  • Iterate contact object i.e. testData in modalData.contactgroups[0].contact Commented Jan 19, 2018 at 12:29
  • I would say: tr(ng-repeat='testData in modalData[0].contactgroups') td {{testData.contact.gsm}} ... Commented Jan 19, 2018 at 12:34
  • see my updated question :) Commented Jan 19, 2018 at 12:35
  • What does that mean: "setModal(groups[$index])" ? Where does "gropus[$index]" comes from? Commented Jan 19, 2018 at 12:39
  • wait will update Commented Jan 19, 2018 at 12:44

2 Answers 2

1

You have to remove [0] from your ng-repeat, then you will get actual array.
Since you have those values under contact object, you have to populate using object and property name. Like,

tr(ng-repeat='testData in modalData.contactgroups')
 td {{testData.contact.gsm}} 
 td {{testData.contact.firstname}}
 td {{testData.contact.lastname}}
Sign up to request clarification or add additional context in comments.

Comments

0

<!DOCTYPE html>
<html ng-app="app">

  <head>
    <meta charset="utf-8" />
    <title>AngularJS Example</title>
    <script data-require="[email protected]" src="https://code.angularjs.org/1.4.3/angular.js" data-semver="1.4.3"></script>
    <script>
      var app = angular.module('app', []);
      app.controller('MainCtrl', function($scope) {
        $scope.items = [
    {
        "contactsCount": 2,
        "id": 1,
        "userKey": "$2a$10$3jCL8.rJV9/KS11MtrB4r.0uE4Fu/rGwEk.ko0HTkzFNiKXhh1.X.",
        "groupname": "Angular",
        "createdAt": "2018-01-15T07:21:42.000Z",
        "updatedAt": "2018-01-15T07:21:42.000Z",
        "contactgroups": [
            {
                "id": 1,
                "contact": {
                    "id": 1,
                    "gsm": "111111111",
                    "firstname": "Mohamed",
                    "lastname": "Sameer"
                }
            },
            {
                "id": 3,
                "contact": {
                    "id": 3,
                    "gsm": "222222222",
                    "firstname": "Rizwan",
                    "lastname": "Riz"
                }
            }
        ]
    }
]
      });
    </script>
  </head>
  <body ng-controller="MainCtrl">
    <table>
      <tr ng-repeat="item in items[0].contactgroups">
        <td ng-repeat="i in item">{{i.gsm}}</td>
        <td ng-repeat="i in item">{{i.firstname}}</td>
        <td ng-repeat="i in item">{{i.lastname}}</td>
      </tr>
    </table>
  </body>
</html>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.