Created
January 21, 2019 07:22
-
-
Save novalagung/6d26d80357c88874e80a91abfc81e8fe to your computer and use it in GitHub Desktop.
This file contains 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
var vm = {} | |
vm.dataUser = [] | |
vm.isDataUserReady = false | |
vm.doGetData = function() { | |
$.ajax({ | |
url: "https://reqres.in/api/users?page=2" | |
}).then(function(res) { | |
setTimeout(() => { | |
vm.dataUser = res.data | |
vm.isDataUserReady = true | |
}, 2000) | |
}) | |
} | |
vm.doSomeProcess = function() { | |
console.log("hello") | |
console.log("test") | |
var doWait = setInterval(function() { | |
if (!vm.isDataUserReady) { | |
return | |
} | |
clearInterval(doWait) | |
// put all process here | |
// example below: | |
var sample = vm.dataUser | |
if (sample.length > 0) { | |
alert("data arrived") | |
} | |
}, 300) | |
} | |
$(function() { | |
vm.doGetData() | |
vm.doSomeProcess() | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment