title: AngularJS: Is it possible to watch a global variable (I.e outside a scope)?
body: <p>Let me start by saying that what I am trying to do is probably not considered good practice. However, I need to do something like this in order to migrate a large web app to AngularJs in small incremental steps.</p>
  
  <p>I tried doing </p>
  
  <pre><code> $scope.$watch(function () { return myVar; }, function (n, old) {
                      alert(n + ' ' + old);
                  });
  </code></pre>
  
  <p>Where myVar is a global variable (defined on window)</p>
  
  <p>And then changing myVar from the console.
  But it only fires when first setting up the watcher. </p>
  
  <p>It works if I update myVar from within the controller (see <a href="http://jsfiddle.net/rasmusvhansen/vsDXz/3/" rel="noreferrer">http://jsfiddle.net/rasmusvhansen/vsDXz/3/</a>, but not if it is updated from some legacy javascript</p>
  
  <p>Is there any way to achieve this?</p>
  
  <p><strong>Update</strong>
  I like Anders' answer if the legacy code is completely off limits. However, at the moment I am looking at this approach which seems to work and does not include a timer firing every second:</p>
  
  <pre><code>// In legacy code when changing stuff    
  $('.angular-component').each(function () {
          $(this).scope().$broadcast('changed');
  });
  
  // In angular
  $scope.$on('changed', function () {
      $scope.reactToChange();
  });
  </code></pre>
  
  <p>I am awarding points to Anders even though I will go with another solution, since his solution correctly solves the problem stated.</p>