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}}
rdonatoiop
  • 1,185
  • 1
  • 14
  • 28

2 Answers2

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.

D--
  • 11
  • 2
  • This is the data I am getting: 1 33126 FEB/11/2014 06 AM 0 2 33126 FEB/11/2014 07 AM 0 I tried {{data.ORDER}} but nothing shows. Pretty sure I'm missing stuff. – user2259122 Feb 11 '14 at 20:27
  • 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. – Steven Scott Feb 11 '14 at 20:51
  • For XML data, try looking at this stack overflow question: http://stackoverflow.com/questions/15490658/how-to-handle-xml-services-in-angularjs – D-- Feb 11 '14 at 21:23
  • Wierd, I am using the data from the following link: http://iaspub.epa.gov/enviro/efservice/getEnvirofactsUVHOURLY/ZIP/33126/JSON – user2259122 Feb 11 '14 at 21:53
  • Cant seem to get the data to come back as JSON. Anyone see something wrong with my code? – user2259122 Feb 11 '14 at 22:25
  • Try changing your URL in your $http.get from http://iaspub.epa.gov/enviro/efservice/getEnvirofactsUVHOURLY/ZIP/33126/JSON%27?callback=callBackFn to http://iaspub.epa.gov/enviro/efservice/getEnvirofactsUVHOURLY/ZIP/33126/JSON?callback=callBackFn (remove the %27). When that is removed, the data I can see on my browser is a JSON array, but when it is there, the data is XML. – D-- Feb 12 '14 at 14:13
  • Tried it...nothing...if someone could plug my code in somewhere and get this to work I can donate some bitcoin... – user2259122 Feb 17 '14 at 15:49
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.

koljaTM
  • 10,064
  • 2
  • 40
  • 42