0

Okay, so I am trying to organize data I am retrieveing from an external API, and I am not sure how to go about it. I am able to get the entire JSON data to show via {{data}}, but how would I go about getting just a property within the data? What I have so far is:

var tanApp = angular.module('tanApp')
.controller('MainCtrl', ['$scope', '$http', function ($scope, $http) {
$scope.awesomeThings = [
  'HTML5 Boilerplate',
  'AngularJS',
  'Karma'
];
$scope.data = 'unknown';
    $http.get('http://iaspub.epa.gov/enviro/efservice/getEnvirofactsUVHOURLY/ZIP/33126/JSON%27?callback=callBackFn').success(function(data){
        $scope.data = data;
});
    tanApp.config(['$httpProvider', function($httpProvider) {
    $httpProvider.defaults.useXDomain = true;
    delete $httpProvider.defaults.headers.common['X-Requested-With'];
    }]);

and in my HTML:

{{data}}

2 Answers 2

0

To display a properties of your data in your HTML page all you have to do is

{{data.yourPropertyName}}

Making use of two way binding and ngRepeat might also come in handy displaying your data.

Sign up to request clarification or add additional context in comments.

7 Comments

This is the data I am getting: <getEnvirofactsUVHOURLYList Count="21" Rows="0-10000"> <getEnvirofactsUVHOURLY> <ORDER>1</ORDER> <ZIP>33126</ZIP> <DATE_TIME>FEB/11/2014 06 AM</DATE_TIME> <UV_VALUE>0</UV_VALUE> </getEnvirofactsUVHOURLY> <getEnvirofactsUVHOURLY> <ORDER>2</ORDER> <ZIP>33126</ZIP> <DATE_TIME>FEB/11/2014 07 AM</DATE_TIME> <UV_VALUE>0</UV_VALUE> </getEnvirofactsUVHOURLY> I tried {{data.ORDER}} but nothing shows. Pretty sure I'm missing stuff.
You are getting XML, not JSON which will expand properly. Can you get the data back as a JSON array? If not, then you need to parse it into a JSON array, and then use a ng-repeat to display it.
For XML data, try looking at this stack overflow question: stackoverflow.com/questions/15490658/…
Wierd, I am using the data from the following link: iaspub.epa.gov/enviro/efservice/getEnvirofactsUVHOURLY/ZIP/…
Cant seem to get the data to come back as JSON. Anyone see something wrong with my code?
|
0

You have an extra character after the JSON and before the ? in your URL. Get rid of it and it will give you proper json instead of (the default?) XML.

1 Comment

Yeah I took that off and no data is coming in at all now.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.