Skip to content

Instantly share code, notes, and snippets.

@47ronin
Last active July 18, 2016 15:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save 47ronin/a853ef9e0bf740779172cac98cb879ac to your computer and use it in GitHub Desktop.
Save 47ronin/a853ef9e0bf740779172cac98cb879ac to your computer and use it in GitHub Desktop.
AngularJS 1.x gather data from promise and do amazing shit
'use strict';
angular.module('someApp')
.controller('MainCtrl',
['$scope', '$http', '$moment', '$q',
function ($scope, $http, $moment, $q) {
var bunchOfShit = 'value',
moreShit = 'anotherValue',
shitURL = 'https://someurl/' + bunchOfShit + '?callback=JSON_CALLBACK',
shitStormURL = 'https://anotherwebsite/' + moreShit + '?callback=JSON_CALLBACK',
dataShit = $http.jsonp(shitURL),
moreData = $http.jsonp(shitStormURL)
];
$q.all([dataShit, moreData])
.then(function (promise) {
var val1 = promise[0].data;
var val2 = promise[1].data;
$scope.amazingShit = $moment(dataShit.time, 'X').format('MMM DD');
$scope.coolShit = Math.round(moreData.awesomeSauce);
$scope.shitStocks = parseFloat(Math.round(dataShit.LastPrice * 100) / 100).toFixed(2);
$scope.shitPercent = moreData.ChangePercent.toFixed(2);
});
}]); // end controller MainCtrl
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment