javascript - How to use the setTimeout with angular -
i have code:
if (xxx == xxx){ var x = 5 + 3; settimeout(function() { $('.regerrmsg').text(""); $scope.errmsg = "hi."; }, 5000); }
i execute function i.e, show "hi" message after 5 seconds. so, code correct. of now, message not showing up. have gone wrong?
my question .. hi executes , waits 5 sec or wait waits 5 secs , shows hi ?
let's consider simplified example
foo(); settimeout(function () {bar();}, 5000); baz();
now it's easier describe happen, step step (in excruciating detail)
- line 1:
foo
gets interpreted ()
invokesfoo
- line 2:
settimeout
gets interpreted - the arguments passed
settimeout
interpreted, i.e. function references set here - the
(/* ... */)
invokessettimeout
settimeout
sets callback invoke argument0
after argument1
milliseconds- line 3:
baz
gets interpreted ()
invokes baz- end of file ...nothing happens while...
- argument
0
(from5
) gets invoked bar
gets interpreted (using references4
)()
invokesbar
as of now, message not showing up. have gone wrong?
it looks change you've made reflected in dom clearing of text .regerrmsg
, perhaps meant use
$('.regerrmsg').text("hi.");
or invoke other method make updated vale of $scope
reflected in #document
Comments
Post a Comment