title: How to get the latest data from a module that is updated from another module in AngularJS
body: <p>I have 3 AngularJS modules, <code>M</code> a module to be the <strong>model</strong> holder/manager, and another 2 modules <code>app</code> which is the main module and <code>A</code> which will manipulate data of <code>M</code> module. Both <code>app</code> and <code>A</code> have dependency on <code>M</code>.</p>
  
  <p>For simplicity, the model is just an array of animals names, and I want to add new names from within module <code>A</code> those I expect to see reflected within the list controlled by <code>app</code> module.</p>
  
  <p>This <a href="https://plnkr.co/edit/rtuejbnm1EjgMuLzvROB?p=preview" rel="nofollow noreferrer">plunk</a> illustrates the case.</p>
  
  <p>I implemented the Mediator Pattern as suggested in this <a href="https://stackoverflow.com/a/27365517/236384">stackoverflow question</a> so my model module <code>M</code> will publish its changes to its subscribers.</p>
  
  <p><code>app</code> has a controller <code>NamesListCtrl</code> that reads data from <code>NamesModel</code> the factory from <code>M</code>, and subscribes to its event <code>NamesModelChanged</code> that is published whenever the inner data inside <code>NamesModel</code> is changed.</p>
  
  <p><strong>The problem</strong>: when the anonymous callback for <code>NamesListCtrl</code> subscription to <code>NamesModelChanged</code> is called (line 87 in plunk), the statement <code>$scope.data.namesList = NamesModel.getAll();</code> will not retrieve the updated data:</p>
  
  <pre><code>NamesModel.subscribe('NamesModelChanged', function() {
    console.log('OK, I will update my data');
    // not getting the updated list
    $scope.data.namesList = NamesModel.getAll();
  });
  </code></pre>
  
  <p>Any help?</p>