Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

I want to extract couple of parameters from json response but somehow I am not able to populate it. I am using angular js and third party api. This is my API result. I just want to display "[{"severity":{"label":"Severe"},"label":"Skin Rash"}]" out of entire array. I need to populate in html in list view.

"an allergy has one or more reactions. each reaction has a severity. label Severe is a key in the Severity object. label Skin Rash is in the reactions object. the allergy object has it's own label field."

{"reactions":[{"severity":{"label":"Severe"},"label":"Skin Rash"}],"audit":{"source":"medicare","createDate":"2015-03-02T18:39:23Z","updateDate":"2015-03-02T18:39:23Z","version":"1"},"label":"Other - IODINE","ended":"2007-10-28T00:00:00-04:00","started":"1993-01-01T00:00:00-05:00","date":"2015-03-02T18:37:42Z"}

share|improve this question
    
I want to know what you have tried until now and which part of the resulting code you have had problems in. –  mico Mar 18 at 20:20

3 Answers 3

Use ng-repeat:

Not sure what you are looking for, but here is an example:

EDIT

var app = angular.module("myApp", []);

app.controller("MyCtrl", function($scope){

var obj = {"reactions":[{
"severity":{"label":"Severe"},
"label":"Skin Rash"}],
"audit":{"source":"medicare","createDate":"2015-03-02T18:39:23Z",
"updateDate":"2015-03-02T18:39:23Z","version":"1"},
"label":"Other - IODINE","ended":"2007-10-28T00:00:00-04:00",
"started":"1993-01-01T00:00:00-05:00",
"date":"2015-03-02T18:37:42Z"}

  $scope.reactions = obj.reactions;

});

In your index.html; you can do the following

<body ng-controller="MyCtrl">
    <table class="table table-bordered">
      <thead>
        <th>Severity label</th>
        <th>Just Label</th>
      </thead>
      <tbody>
        <tr ng-repeat="item in reactions">
          <td>{{item.severity.label}}</td>
          <td>{{item.label}}</td>
        </tr>
      </tbody>
    </table>
  </body>

Here is the Plunk: http://plnkr.co/edit/sgJ9RvtUYl6DkUDXPCc6?p=preview

share|improve this answer
    
Thanks for your response. I tried with the syntax which you mentioned here.I am able to display object but not actual value. "[{"severity":{"label":"Severe"},"label":"Skin Rash"}]". How can I display actual value. like "Skin Rash" –  user1528581 Mar 18 at 20:30
    
Check if inserting "label" in the reactions array works. –  user3681587 Mar 18 at 20:34
    
If I am using reactions[0].severity then it is displaying only "Severe" but I want to display "Skin Rash". Close call but not getting it. –  user1528581 Mar 18 at 20:45
    
item.reactions[0].severity.label <--this might work –  user3681587 Mar 18 at 20:48

This should work!

HTML

<div ng-controller="ctrl">
    <div ng-repeat="item in data.reactions">
        {{item.label}}
    </div>
</div>

JAVASCRIPT

var myApp = angular.module('myApp', []);

myApp.controller('ctrl', function ($scope) {
$scope.data = {
    "reactions":[
        {
            "severity":
            {
                "label":"Severe"
            },
            "label":"Skin Rash"
        }
    ],
    "audit":
    {
        "source":"medicare",
        "createDate":"2015-03-02T18:39:23Z",
        "updateDate":"2015-03-02T18:39:23Z",
        "version":"1"
    },
    "label":"Other - IODINE",
    "ended":"2007-10-28T00:00:00-04:00",
    "started":"1993-01-01T00:00:00-05:00",
    "date":"2015-03-02T18:37:42Z"
};
});
share|improve this answer

You can try:

<ul ng-repeat="item in data.reactions">
  {{item.label}}
</ul>
share|improve this answer
    
This does not provide an answer to the question. To critique or request clarification from an author, leave a comment below their post - you can always comment on your own posts, and once you have sufficient reputation you will be able to comment on any post. –  Marvin Emil Brach Mar 19 at 8:11
    
@MarvinEmilBrach This answer totally try to answer the question... –  Getz Mar 19 at 9:13
    
It tries, but it does not! At first it just repeats the 'ul' instead of an 'li'... Further he wants to contain the label of "severity"... And last but not least, if an answer to a question starts with "try that" you could bet on that it should be a comment instead... –  Marvin Emil Brach Mar 19 at 9:46

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.