0

I am learning a Angular and I'm stuck with one task. I have three parts in my app a View, service and controller, View look like this:

<body ng-app="ForecastApp">

    <nav class="navbar navbar-inverse navbar-fixed-top">
      <div class="container-fluid">

          <p class="navbar-brand">Week Forecast</p>

      </div>
    </nav>

    <div class="container-fluid"  class="main" ng-controller="MainController">
      <div class="row">
        <div class="col-sm-3 col-md-2 sidebar">
          <h2><span class="label label-info">Search for a City</span></h2>
          <div class="input-group">

            <input type="text" class="form-control" placeholder="City name...">
              <span class="input-group-btn">
            <button class="btn btn-default" type="button">Go!</button>
          </span>
          </div>
        </div>
        <div class="col-sm-9 col-sm-offset-3 col-md-10 col-md-offset-2 main">
          <h1 class="page-header">{{ fiveDay.city.name }}</h1>

          <div class="forecast" ng-repeat="day in fiveDay.days">

              </div>
              </div>

        </div>
      </div>
    </div>
</body>

The service look like this:

app.factory('forecast', ['$http', function($http) { 
  return $http.get('http://api.openweathermap.org/data/2.5/forecast/city?q=Warsaw&units=metric&mo') 
            .success(function(data) { 
              return data; 
            }) 
            .error(function(err) { 
              return err; 
            }); 
}]);

And the controller look like this:

app.controller('MainController', ['$scope', 'forecast', function($scope, forecast) {

  forecast.success(function(data) { 
    $scope.fiveDay = data; 
  });

}]);

Data for this lesson is take from the rest api from here http://api.openweathermap.org/data/2.5/forecast/city?q=Warsaw&units=metric&mo

How can I go throw all this json resposne and display all the items from the array "list" from this json, for example to look like this:

Date: "2015-06-12 15:00:00" description: "few clouds" temp: 26.82 pressure: 1015.2

4
  • 1
    Post the JSON please. Commented Jun 12, 2015 at 17:35
  • 1
    @TheHeadRush here: api.openweathermap.org/data/2.5/forecast/… Commented Jun 12, 2015 at 17:37
  • pastebin.com/htiWAFjZ Commented Jun 12, 2015 at 17:37
  • There is no days property for that JSON response, there is a list property where you meaning to use that? Commented Jun 12, 2015 at 17:39

1 Answer 1

2

As I see its simple JSON you can traverse through it using . & whenever required mention index of it to get the value.

Code

$scope.fiveDays = data.list

Markup

<div class="forecast" ng-repeat="day in fiveDays ">
   <div>Date : {{dt|date: 'yyyy-dd-MM'}}</div>
   <div>description: {{weather[0].description}}</div>
   <div>temp: {{main.temp}}</div>
   <div>pressure: {{main.pressure}}</div>
</div>

Different angular date filter format

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

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.