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)

  1. line 1: foo gets interpreted
  2. () invokes foo
  3. line 2: settimeout gets interpreted
  4. the arguments passed settimeout interpreted, i.e. function references set here
  5. the (/* ... */) invokes settimeout
  6. settimeout sets callback invoke argument 0 after argument 1 milliseconds
  7. line 3: baz gets interpreted
  8. () invokes baz
  9. end of file ...nothing happens while...
  10. argument 0 (from 5) gets invoked
  11. bar gets interpreted (using references 4)
  12. () invokes bar

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

Popular posts from this blog

javascript - how to protect a flash video from refresh? -

android - Associate same looper with different threads -

visual studio 2010 - Connect to informix database windows form application -