title: AngularJS array not updating when using ng-view
body: <p>I am learning how to use ngRoute to split my html forms into separate views. When I add data to the main array in the index.html the array updates correctly, but when I try the same approach in the html forms that are added in through the ng-view, the array does not render correctly. I can debug and see that the array is getting the new name added, but it will not render on the html.</p>
  
  <p>Index.html
      </p>
  
  <pre><code>&lt;h1&gt; Names &lt;/h1&gt;
  
  &lt;ul ng-repeat="name in names"&gt;
      &lt;li&gt;{{name.fname}}&lt;/li&gt;
  &lt;/ul&gt;
  
  &lt;h1&gt;Add name in index.html&lt;/h1&gt;
  &lt;input type="text" ng-model="name" /&gt;
  &lt;button ng-click="addName(name)"&gt;add name&lt;/button&gt;
  
  &lt;ul&gt;
      &lt;li&gt;&lt;a href="#/first"&gt; First&lt;/a&gt;&lt;/li&gt;
      &lt;li&gt;&lt;a href="#/second"&gt; Second&lt;/a&gt;&lt;/li&gt;
  &lt;/ul&gt;
  
  &lt;div class="container"&gt;
      &lt;div ng-view&gt;&lt;/div&gt;
  &lt;/div&gt;
  </code></pre>
  
  <p>
  </p>
  
  <p>Apps.js</p>
  
  <pre><code>var myApp = angular.module('myApp', ['ngRoute']);
  
  myApp.config(function ($routeProvider) {
  $routeProvider
  .when('/first', {
      templateUrl: 'pages/first.html',
      controller: 'mainController'
  })
  
  .when('/second', {
      templateUrl: 'pages/second.html',
      controller: 'mainController'
  })
  
  });
  
  myApp.controller('mainController', ['$scope', '$log', function($scope, $log) {
  $scope.names = [{fname:'john',lname:'doe'},{fname:'jane',lname:'doe'}];
  
   $scope.addName = function(name){
      $scope.names.push({fname:name,lname:'no last name'});     
  }
  }]);
  </code></pre>
  
  <p>first and second.html are identical </p>
  
  <pre><code>&lt;h1&gt;Add name in first.html&lt;/h1&gt;
  &lt;input type="text" ng-model="name" /&gt;
  &lt;button ng-click="addName(name)"&gt;add name&lt;/button&gt;
  </code></pre>
  
  <p><a href="https://i.stack.imgur.com/na1BQ.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/na1BQ.png" alt="enter image description here"></a></p>