Last active
July 18, 2016 15:58
-
-
Save 47ronin/a853ef9e0bf740779172cac98cb879ac to your computer and use it in GitHub Desktop.
AngularJS 1.x gather data from promise and do amazing shit
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'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