Skip to content

Instantly share code, notes, and snippets.

@anaumov
Created October 28, 2015 07:50
Show Gist options
  • Save anaumov/726d46ec26cc13ee07b7 to your computer and use it in GitHub Desktop.
Save anaumov/726d46ec26cc13ee07b7 to your computer and use it in GitHub Desktop.
Использование промисов
function loadCountries(){
$http.get('http://api.com/countries')
}
var allCountries = [];
// летит запрос на сервер, ждем ответа, после ответа заполняем массив
loadCountries().then(function(data){
allCountries = data.countries
})
// запрос на серве не летит, не надо ждать ответа, данные появляются мнговенно
setTimeout(function(){
loadCountries().then(function(data){
console.log(data.countries);
})
}, 60000)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment