title: AngularJs OrderBy after push into an array in ng-repeat
body: <p>I'm trying to sort an array after pushing a new element to it and show changes on my ng-repeat. It isn't working as expected, it looks like my scope is disconnected from the view.</p>
  
  <p>I have a people array shown with a ng-repeater. Then a column header to sort the array by Last Name. Finally a button to add a new person and automatically sort the array by First Name and show it on the view.</p>
  
  <p>This is my HTML code:</p>
  
  <p>(<a href="https://jsfiddle.net/ivanarandaa/509xp9kf/20/" rel="nofollow noreferrer">I also have a fiddler here</a>)</p>
  
  <p>Thanks!!</p>
  
  <pre><code>&lt;div ng-app="myApp"&gt;
    &lt;div ng-controller='myController'&gt;
      &lt;div&gt;
        &lt;input type="button" value="Filter All" ng-click="filterAll()" /&gt;
        &lt;input type="button" value="Add &amp; Filter" ng-click="AddNFilter()" /&gt;
      &lt;/div&gt;&lt;br/&gt;
      &lt;div&gt;&lt;a href="" ng-click="orderByField='lname'; reverseSort = !reverseSort"&gt;Order by LName&lt;/a&gt;&lt;/div&gt;
      &lt;div ng-repeat="p in person | orderBy:orderByField:reverseSort"&gt;
        {{p.name}} {{p.lname}}
      &lt;/div&gt;
    &lt;/div&gt;
  &lt;/div&gt;
  </code></pre>
  
  <p>And my javascript:</p>
  
  <pre><code>var app = angular.module('myApp', []);
  app.controller('myController', function ($scope, $filter) {
      var person = [{
              name: "Seimour"
              , lname: "Duncan"
          }
          , {
              name: "Engy"
              , lname: "Wook"
          }
          , {
              name: "Dame"
              , lname: "Eyola"
        }];
      $scope.person = person;
      $scope.filterAll = function () {
          alert('Before filter: ' + $scope.person[0].name);
          var filtered = $filter('orderBy')($scope.person, 'name');
          $scope.person = filtered;
          alert('After filter: ' + $scope.person[0].name);
      }
      $scope.AddNFilter = function () {
          var p = [{
              name: "Ayesha"
              , lname: "Shexper"
          }];
          alert('Length before adding: ' + $scope.person.length);
          $scope.person.push(p);
          var filtered = $filter('orderBy')($scope.person, 'name');
          $scope.person = filtered;
          alert('Length after adding: ' + $scope.person.length);
      }
  });
  </code></pre>