In angular JS, if you want perform some action after some time (or you want to wait for some time) you can use $timeout service. This service returns the promise which we can resolve by "then". In following example, it will take 2 seconds to call the function "toBeCalled".
function Controller($timeout) {
wait(2).then(function () {
})
function wait(seconds) {
return $timeout(toBeCalled, seconds * 1000);
}
function toBeCalled() {
console.log("called after 2 seconds");
}
}
function Controller($timeout) {
wait(2).then(function () {
})
function wait(seconds) {
return $timeout(toBeCalled, seconds * 1000);
}
function toBeCalled() {
console.log("called after 2 seconds");
}
}