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:
foogets interpreted ()invokesfoo- Line 2:
setTimeoutgets interpreted - The arguments to be passed into
setTimeoutare interpreted, i.e. function references set here - The
(/* ... */)invokessetTimeout setTimeoutsets up a callback to invoke argument0after argument1milliseconds- Line 3:
bazgets interpreted ()invokes baz- End of file ...nothing happens for a while...
- argument
0(from5) gets invoked bargets 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.