silvrgit/app/js/temp.js

54 lines
1.5 KiB
JavaScript
Raw Normal View History

2016-03-08 21:52:21 +00:00
var app = angular.module( "Temp", [])
.controller("TempController", function( $scope, tempService) {
$scope.tempData = [];
loadRemoteData();
function applyRemoteData(newData)
{
$scope.tempData = newData;
}
function loadRemoteData() {
console.log('Loading data...');
tempService.getTemp()
.then(
function(tempData) {
applyRemoteData(tempData);
}
)
}
}
).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));
}
function handleError(response) {
if ( !angular.isObject(response.data) || !response.data.message) {
return( $q.reject("An unknown error occured"));
}
return($q.reject(response.data.message));
}
function handleSuccess(response)
{
return(response.data);
}
}
);