Issue
I have the code:
if (xxx == xxx){
var x = 5 + 3;
setTimeout(function() {
$('.regErrMsg').text("");
$scope.errMsg = "Hi.";
}, 5000);
}
I would like to execute the function i.e, show "Hi" message after 5 seconds. So, is my code correct. As of now, the message is not showing up. Where have I gone wrong?
Solution
My question is .. does the Hi executes and then it waits for 5 sec or wait waits for 5 secs and then shows Hi ?
Let's consider a simplified example
foo();
setTimeout(function () {bar();}, 5000);
baz();
Now it's easier to describe what will happen, step by step (in excruciating detail)
- Line 1:
foo
gets interpreted ()
invokesfoo
- Line 2:
setTimeout
gets interpreted - The arguments to be passed into
setTimeout
are interpreted, i.e. function references set here - The
(/* ... */)
invokessetTimeout
setTimeout
sets up a callback to invoke argument0
after argument1
milliseconds- Line 3:
baz
gets interpreted ()
invokes baz- End of file ...nothing happens for a while...
- argument
0
(from5
) gets invoked bar
gets interpreted (using references from4
)()
invokesbar
As of now, the message is not showing up. Where have I gone wrong?
It looks like the only change you've made that will be reflected in the DOM is the clearing of text from .regErrMsg
, perhaps you meant to use
$('.regErrMsg').text("Hi.");
or invoke some other method which will make the updated vale of $scope
be reflected in the #document
Answered By - Paul S.
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.