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:
foogets interpreted ()invokesfoo- line 2:
settimeoutgets interpreted - the arguments passed
settimeoutinterpreted, i.e. function references set here - the
(/* ... */)invokessettimeout settimeoutsets callback invoke argument0after argument1milliseconds- line 3:
bazgets interpreted ()invokes baz- end of file ...nothing happens while...
- argument
0(from5) gets invoked bargets 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