Simple get service angular
Creating a simple service with angular through $http and listing dates with ng-repeat.
by Lucas Silva
HTML
<div ng-app>
<div ng-controller="ServerController">
<h1>{{dadosRequest.city_name}}</h1>
<div ng-repeat="day in dadosRequest.days">
<p>{{day.datetime | date}}</p>
<p>{{day.high}}</p>
<img ng-src="{{day.icon}}" />
<p>{{day.low}}</p>
</div>
</div>
<div>
{{dadosRoot.city_name}}
</div>
</div>
CSS
img {
max-height: 30px;
max-width:30px;
}
JavaScript
function ServerController($scope, $http, $rootScope) {
$http.get('https://s3.amazonaws.com/codecademy-content/courses/ltp4/forecast-api/forecast.json')
.success(function(data) {
$scope.dadosRequest = data;
$rootScope.dadosRoot = data;
console.log($rootScope.dadosRoot);
})
.error(function(err) {
return err;
});
}