title: In an Angular.js controller's scope function code doesn't run below a $timeout statement inside
body: <p>I have a button for which I have set <code>ng-click=&quot;refresh()&quot;</code>. The console logs before the timeout function logs correctly but the console log inside the <code>$timeout</code> block and after the block doesn't seem to log. If I remove the <code>$timeout</code> block every console log works. I even checked with <code>$interval</code> instead of <code>$timeout</code> but same behaviour.</p>
  <p>I wanted to do something like this <a href="https://plnkr.co/edit/tXnA9tKJg22hBuXNSepv?p=preview&amp;preview" rel="nofollow noreferrer">here</a></p>
  <p>I'm using Angular.js 1.4.0</p>
  <p>This is my implementation inside the controller</p>
  <pre class="lang-js prettyprint-override"><code>      $scope.refreshing ={state: false};
        $scope.refresh = function(){
          console.log($scope);
          $scope.refreshing.state = true;
          $scope.search(); //sends an http request and loads results.
          console.log('this logs');
          // $scope.refreshing.state = false;
          $timeout(function(){
             console.log('this doesnt log')
             $scope.refreshing.state = false;
           },2000);
          console.log('this doesnt log')
  
        }
  </code></pre>