Created
July 19, 2016 03:09
-
-
Save sejr/560b3cdb7f374a095e75cd04885db8b1 to your computer and use it in GitHub Desktop.
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
| function loadPkmn(start, end) { | |
| for (var i = start; i <= end; i++) { | |
| $http.get('https://pokeapi.co/api/v2/pokemon/' + i).then(function(res) { | |
| $scope.$apply(function() { | |
| $scope.kantoPkmn.push(res.data); | |
| }); | |
| }) | |
| } | |
| } | |
| loadPkmn(kanto.start, kanto.end); |
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
| .service('pkmnService', ['$http', '$q', function($http, $q) { | |
| var deferObject, | |
| pkmnMethods = { | |
| getPromise: function(start, end) { | |
| var promises = []; | |
| var deferObject = deferObject || $q.defer(); | |
| for(var i = start; i <= end; i++) { | |
| var promise = $http.get('https://pokeapi.co/api/v2/pokemon/' + i); | |
| promises.push(promise); | |
| } | |
| $q.all(promises).then(function(values) { | |
| }); | |
| return deferObject.promise; | |
| } | |
| // getPromise: function() { | |
| // var promise = $http.get('https://pokeapi.co/api/v2/pokemon/'), | |
| // deferObject = deferObject || $q.defer(); | |
| // promise.then( | |
| // // OnSuccess function | |
| // function(answer){ | |
| // deferObject.resolve(answer); | |
| // }, | |
| // function(reason){ | |
| // deferObject.reject(reason); | |
| // }); | |
| // return deferObject.promise; | |
| // } | |
| }; | |
| return pkmnMethods; | |
| }]); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment