Skip to content

Instantly share code, notes, and snippets.

@nausik
Last active August 29, 2015 14:16
Show Gist options
  • Select an option

  • Save nausik/7b55638a75211245dc95 to your computer and use it in GitHub Desktop.

Select an option

Save nausik/7b55638a75211245dc95 to your computer and use it in GitHub Desktop.
Fun stuff with promises
<html>
<body ng-app = "testapp">
<div id ng-controller = "TestController as test"></div>
</body>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<script src="angular.min.js"></script>
<script>
var app = angular.module('testapp', []);
app.controller('TestController', ['WatFactory', function(wat){
var result = wat.test();
setTimeout(function(){
console.log(result.$$state.value.data);
}, 10000);
//somehow equal to
result.then(function(response){
console.log(response.data);
})
}]);
app.factory('WatFactory', ['$http', function($http){
return {
test: function(){
return $http.get('http://ws.audioscrobbler.com/2.0/?method=artist.gettoptracks&artist=weezer&api_key=4519cf1957867d0ef1c8fafb92732a21&format=json').then(function(response){
return response;
});
}
}
}]);
</script>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment