Simple Angular $http.get and ng-repeat sample

We’ll start with the html code of our httpGet.html page. It should be pretty obvious that this will loop through something called weathers.list (weathers is a JSON object containing a property named ‘list’, which contains a list of weather details. We are going to show the .main.temp property of each of those list items.

    <li  ng-repeat="thing in weathers.list">

Our controller is that pulls the data from an API using $http.get and loads the return value into a $scope variable named ‘weathers’ is very simple:

//we need to inject the $http service 
myApp.controller('httpGetController',['$scope', '$http', function($scope, $http){
     $scope.pageName = 'httpGet';
         $scope.weathers = result; //it returns a json list of weather

That is all it takes for a basic GET and then loading the json data into a webpage.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s