title: How do I update a value in an AngularJS (with TypeScript) controller when a value on an injected service updates
body: <p>At the moment I am trying to learn Typescript and AngularJS coming from a background of Actionscript. I have been playing around with some code experiments and van generally achieve what I want to but not always in the way that I would like!</p>
  
  <p>At the moment I have this code:</p>
  
  <pre><code>export class CountingService
  {
      countScope = { count : 0 };
  
      public increment()
      {
          this.countScope.count++;
      }
  }
  
  export class PageController
  {
      constructor( private service : CountingService )
      {
          this.countScope = service.countScope;
      }
  
      public localCount : number = 0;
  
      countScope;
  
      public increment()
      {
          this.service.increment();
  
          this.localCount++;
      }
  
  }
  </code></pre>
  
  <p>and I have a few different views that have this code in:</p>
  
  <pre><code>&lt;div ng-controller="PageController as page"&gt;
  
      &lt;Button ng-click="page.increment()"&gt;Count {{page.localCount}}/{{page.countScope.count}}&lt;/Button&gt;
  
  &lt;/div&gt;
  </code></pre>
  
  <p>When I switch between the views the localCount always resets to zero but the count in the countScope from the service does not reset and is incremented by each different controller.</p>
  
  <p>This works but it's a bit messy. I have to have the untyped localScope floating around and the views need to know about the internal structure of the countScope object and bind to page.countScope.count rather than something like page.globalCount.</p>
  
  <p>In Actionscript I would have a read only getting on the controller. The service would dispatch an event each time the value changed and the controller would listen for this and then update it's own property which would then update the view.</p>
  
  <p>My question is what is the best practice way to achieve what I am doing here that does not require the view to have knowledge of the internals of an untyped object.
  I am pretty sure that public getters do not exist but can I dispatch and listen for an event?</p>
  
  <p>Many Thanks</p>