old-silvrgit/app/js/temp.js

54 lines
1.5 KiB
JavaScript
Raw Permalink Normal View History

2016-02-18 12:21:04 +00:00
var app = angular.module( "Temp", [])
.controller("TempController", function( $scope, tempService) {
2016-02-18 10:56:59 +00:00
2016-02-18 12:21:04 +00:00
$scope.tempData = [];
2016-02-18 10:56:59 +00:00
2016-02-18 12:21:04 +00:00
loadRemoteData();
2016-02-18 10:56:59 +00:00
2016-02-18 12:21:04 +00:00
function applyRemoteData(newData)
{
$scope.tempData = newData;
}
2016-02-18 10:56:59 +00:00
2016-02-18 12:21:04 +00:00
function loadRemoteData() {
console.log('Loading data...');
tempService.getTemp()
.then(
function(tempData) {
applyRemoteData(tempData);
}
)
}
2016-02-18 10:56:59 +00:00
}
2016-02-18 12:21:04 +00:00
).service(
"tempService",
function($http, $q) {
return({getTemp:getTemp});
function getTemp() {
var request = $http({
method: "get",
url:"http://api.silvrtree.co.uk/temp/all",
params: {
/* action:"get"*/
}
});
return (request.then(handleSuccess, handleError));
}
2016-02-18 10:56:59 +00:00
2016-02-18 12:21:04 +00:00
function handleError(response) {
if ( !angular.isObject(response.data) || !response.data.message) {
return( $q.reject("An unknown error occured"));
2016-02-18 10:56:59 +00:00
}
2016-02-18 12:21:04 +00:00
return($q.reject(response.data.message));
2016-02-18 10:56:59 +00:00
}
2016-02-18 12:21:04 +00:00
function handleSuccess(response)
{
return(response.data);
}
2016-02-18 10:56:59 +00:00
}
2016-02-18 12:21:04 +00:00
);