1

I've posted my code below along with the JSON data I want to display. Specifically, I want to be able to do {{client.label}} and have the clients in a list. Unfortunately the only thing that works is when I do {{client}} which gives me the entire JSON object, which I don't want. I'm new to Angular, and I know I'm obviously doing something wrong but I'm not quite sure what. Any help is appreciated!

<body ng-controller="myController">
  <ul>
    <li ng-repeat="client in userData">
      {{client.label}}
    </li>
  </ul>
  <script>
    var app = angular.module('myApp', []);
    app.controller("myController", function ($scope, $http) {
      $http({
        url: 'myURL/blah/blah',
        method: 'POST',
        data: {
          common: { clientName: '6012' },
          qualifier: '$ALL.$ALL.$ALL.$ALL.$ALL',
          pattern: 'configs\\..*'
        },
        headers: { 'Content-Type': 'application/json' }
      }).success(function(data) {
        $scope.userData = data;
      });
    });
  </script>
</body>
{
  "data": {  
    "parameters": [  
      {  
        "qualifier": "$ALL.$ALL.$ALL.$ALL.$ALL",
        "key": "themes",
        "value": {  
          "amairlines": {  
            "id": "amairlines",
            "label": "American Airlines"
          },
          "amazonfork": {  
            "id": "amazonfork",
            "label": "Amazon Fork"
          },
          "bestbuy": {  
            "id": "bestbuy",
            "label": "Best Buy"
          },
          "botw": {  
            "id": "botw",
            "label": "Bank of the West"
          },
          "bbva": {  
            "id": "bbva",
            "label": "BBVA"
          },
          "redleaf": {  
            "id": "redleaf",
            "label": "Red Leaf"
          },
          "citi": {  
            "id": "citi",
            "label": "Citi"
          },
          "costco": {  
            "id": "costco",
            "label": "Costco"
          },
          "firstcitizens": {  
            "id": "firstcitizens",
            "label": "First Citizens"
          },
          "publix": {  
            "id": "publix",
            "label": "Publix"
          },
          "homedepot":{  
            "id": "homedepot",
            "label": "Home Depot"
          },
          "hsbc": {  
            "id":"hsbc",
            "label": "HSBC"
          },
          "huntington": {  
            "id": "huntington",
            "label": "Huntington"
          },
          "kohls": {  
            "id": "kohls",
            "label": "Kohls"
          },
          "nordstrom": {  
            "id": "nordstrom",
            "label": "Nordstrom"
          },
          "paypal": {  
            "id": "paypal",
            "label": "PayPal"
          },
          "primax": {  
            "id": "primax",
            "label": "Primax"
          },
          "td": {  
            "id": "td",
            "label": "Toronto Dominion"
          },
          "usaa": {  
             "id": "usaa",
             "label": "USAA"
          }
        }
      }
    ]
  }
}
1
  • Use ng-repeat in the HTML to iterate over the list. Commented Jul 1, 2016 at 14:45

2 Answers 2

2

Change the ng-repeat to this:

<li ng-repeat="client in userData.parameters[0].value">
  {{client.label}}
</li>
Sign up to request clarification or add additional context in comments.

1 Comment

Thank you! Works just as I wanted, I'll accept this answer as soon as it lets me
1

The data you want to iterate over is not the data that is returned but deeper. You should change $scope = data; to $scope = data.parameters[0].value; Or change the way it is retuned.

One more thing, usually it's better to handle data through a centralized service.

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.