title: updating the array in angularJS
body: <p>angularJS code:</p>
  
  <pre><code>appModule.controller('dcrlistingCtrl',
      ['$scope', '$modal', '$state', '$rootScope', 'loginService', 'servicePOST', 'appConstants', 'sessionService', '$http',
      function ($scope, $modal, $state, $rootScope, loginService, servicePOST, appConstants, sessionService, $http) {
          alert("trial");
  
          $scope.contact = "Doctors";
          $scope.contacts =
                  [
                      { "patch": "BARIJPUR", "contact": ["RAMA SENA", "SMRITI IRANI", "JAGDISH NAIR"] },
                      { "patch": "Anna", "contact": ["ASHISH NAIK", "SMRITI IRANI", "SAIRAJ NAIK"] },
                      { "patch": "Peter", "contact": ["RATAN PANDEY", "RAMAN SHIVOLKAR"] }
                  ];
  
  
          $scope.doctors = function () {
              $scope.contact = "Doctors";
  
              $scope.contacts = [];
  
              $scope.contacts =
                      [
                          { "patch": "BARIJPUR", "contact": ["RAMA SENA", "SMRITI IRANI", "JAGDISH NAIR"] },
                          { "patch": "RATANGHAR", "contact": ["ASHISH NAIK", "SMRITI IRANI", "SAIRAJ NAIK"] },
                          { "patch": "BHIRJ", "contact": ["RATAN PANDEY", "RAMAN SHIVOLKAR"] }
                      ];
  
          };
  
          $scope.pharmacists = function () {
              $scope.contact = "pharmacists";
  
              $scope.contacts = [];
  
              $scope.contacts =
              [
                  { "patch": "DRAMAPUR", "contact": ["RYAN DCOSTA", "SIDDESH NAIK", "ARVIND CHARI"] },
                  { "patch": "MAHALSA", "contact": ["TANVI REDKAR", "PRIYANKA BANDODKAR", "GIRISH MATARBHOG"] }
              ];
          };
  
          $scope.stockists = function () {
              $scope.contact = "stockists";
  
              $scope.contacts = [];
  
              $scope.contacts =
                      [
                          { "patch": "SRIJAN", "contact": ["SHILPA NAIK", "ARBAAZ SHAIK", "NAZEEF SHAIK"] },
                          { "patch": "KHANCHAR", "contact": ["AVESH NAIK", "MELROY FERNANDES", "BRIAN DIAS"] },
                          { "patch": "TRINSAL", "contact": ["MEENAKSHI TIWARI", "GAURAV TIWARI"] }
                      ];
  
          };
  
      }
  ])
  </code></pre>
  
  <p>html code:</p>
  
  <pre><code>&lt;nav class="navbar navbar-default"&gt;
      &lt;div class="container-fluid"&gt;
          &lt;!-- Brand and toggle get grouped for better mobile display --&gt;
          &lt;div class="navbar-header"&gt;
  
  
              &lt;button type="button" type="button" class="navbar-toggle collapsed" style="float:right;" data-toggle="collapse" data-target="#bs-example-navbar-collapse-1" aria-expanded="false"&gt;
                  &lt;span class="sr-only"&gt;Toggle navigation&lt;/span&gt;
                  &lt;span class="glyphicon glyphicon-option-vertical" style="float:right;"&gt;&lt;/span&gt;
              &lt;/button&gt;
  
  
              &lt;button type="button" class="navbar-toggle collapsed" style="float:left;" data-toggle="collapse" data-target="#bs-example-navbar-collapse-1" aria-expanded="false"&gt;
                  &lt;span class="sr-only"&gt;Toggle navigation&lt;/span&gt;
                  &lt;span class="icon-bar"&gt;&lt;/span&gt;
                  &lt;span class="icon-bar"&gt;&lt;/span&gt;
                  &lt;span class="icon-bar"&gt;&lt;/span&gt;
              &lt;/button&gt;
              &lt;div class="text-center visible-xs"&gt;
                  &lt;span&gt; &lt;b&gt; Field Work &lt;/b&gt; &lt;/span&gt;
              &lt;/div&gt;
          &lt;/div&gt;
  
          &lt;!-- Collect the nav links, forms, and other content for toggling --&gt;
          &lt;div class="collapse navbar-collapse text-center" id="bs-example-navbar-collapse-1"&gt;
              &lt;span&gt; &lt;b&gt;Field Work&lt;/b&gt; &lt;/span&gt;
          &lt;/div&gt;&lt;!-- /.navbar-collapse --&gt;
      &lt;/div&gt;&lt;!-- /.container-fluid --&gt;
  &lt;/nav&gt;
  
  
  &lt;div class="container-fluid"&gt;
      &lt;div class="row"&gt;
          &lt;div class="col-sm-2 hidden-xs"&gt;
  
              &lt;ul class="list-group text-center" style="cursor:pointer;"&gt;
                  &lt;li class="list-group-item" id="heading" style="cursor:default;"&gt;{{contact}}&lt;/li&gt;
                  &lt;div ng-repeat="con in contacts"&gt;
                      &lt;li class="list-group-item" id="patch" data-toggle="collapse" data-target='#Dright{{$index}}'&gt;{{con.patch}}&lt;span class="badge"&gt;5&lt;/span&gt;&lt;/li&gt;
                      &lt;div class="text-center collapse" id='Dright{{$index}}'&gt;
                      &lt;div class="cell" ng-repeat="cell in con.contact"&gt;
                      &lt;li class="list-group-item"&gt;{{cell}}&lt;/li&gt;
                      &lt;/div&gt;
                      &lt;/div&gt;
                  &lt;/div&gt;
              &lt;/ul&gt;
  
  
          &lt;/div&gt;
  
          &lt;div class="col-sm-7"&gt;
  
              &lt;div class="col-sm-12"&gt;
                  &lt;button type="button" class="btn btn-primary " ng-click="doctors()"&gt;&lt;b&gt;Doctor&lt;/b&gt;&lt;/button&gt;
                  &lt;button type="button" class="btn btn-primary " ng-click="pharmacists()"&gt;&lt;b&gt;Pharmacist&lt;/b&gt;&lt;/button&gt;
                  &lt;button type="button" class="btn btn-primary " ng-click="stockists()"&gt;&lt;b&gt;Stockist&lt;/b&gt;&lt;/button&gt;
  
              &lt;/div&gt;
  
  
  
              &lt;div class="col-sm-12"&gt;
                  &lt;table class="table"&gt;
                      &lt;thead&gt;
                          &lt;tr&gt;
                              &lt;th&gt;Firstname&lt;/th&gt;
                              &lt;th&gt;Lastname&lt;/th&gt;
                              &lt;th&gt;Email&lt;/th&gt;
                              &lt;th&gt;Firstname&lt;/th&gt;
                              &lt;th&gt;Lastname&lt;/th&gt;
                              &lt;th&gt;Email&lt;/th&gt;
                              &lt;th&gt;Firstname&lt;/th&gt;
                              &lt;th&gt;Lastname&lt;/th&gt;
                              &lt;th&gt;Email&lt;/th&gt;
                              &lt;th&gt;Firstname&lt;/th&gt;
                              &lt;th&gt;Lastname&lt;/th&gt;
                              &lt;th&gt;Email&lt;/th&gt;
                          &lt;/tr&gt;
                      &lt;/thead&gt;
                      &lt;tbody&gt;
                          &lt;tr class="success"&gt;
                              &lt;td&gt;John&lt;/td&gt;
                              &lt;td&gt;Doe&lt;/td&gt;
                              &lt;td&gt;john@example.com&lt;/td&gt;
                              &lt;td&gt;John&lt;/td&gt;
                              &lt;td&gt;Doe&lt;/td&gt;
                              &lt;td&gt;john@example.com&lt;/td&gt;
                              &lt;td&gt;John&lt;/td&gt;
                              &lt;td&gt;Doe&lt;/td&gt;
                              &lt;td&gt;john@example.com&lt;/td&gt;
                              &lt;td&gt;john@example.com&lt;/td&gt;
                              &lt;td&gt;John&lt;/td&gt;
                              &lt;td&gt;Doe&lt;/td&gt;
                              &lt;td&gt;john@example.com&lt;/td&gt;
                          &lt;/tr&gt;
                          &lt;tr class="danger"&gt;
                              &lt;td&gt;Mary&lt;/td&gt;
                              &lt;td&gt;Moe&lt;/td&gt;
                              &lt;td&gt;mary@example.com&lt;/td&gt;
                              &lt;td&gt;Mary&lt;/td&gt;
                              &lt;td&gt;Moe&lt;/td&gt;
                              &lt;td&gt;mary@example.com&lt;/td&gt;
                              &lt;td&gt;John&lt;/td&gt;
                              &lt;td&gt;Doe&lt;/td&gt;
                              &lt;td&gt;john@example.com&lt;/td&gt;
                              &lt;td&gt;john@example.com&lt;/td&gt;
                              &lt;td&gt;John&lt;/td&gt;
                              &lt;td&gt;Doe&lt;/td&gt;
                              &lt;td&gt;john@example.com&lt;/td&gt;
                          &lt;/tr&gt;
                          &lt;tr class="info"&gt;
                              &lt;td&gt;July&lt;/td&gt;
                              &lt;td&gt;Dooley&lt;/td&gt;
                              &lt;td&gt;july@example.com&lt;/td&gt;
                              &lt;td&gt;July&lt;/td&gt;
                              &lt;td&gt;Dooley&lt;/td&gt;
                              &lt;td&gt;july@example.com&lt;/td&gt;
                              &lt;td&gt;John&lt;/td&gt;
                              &lt;td&gt;Doe&lt;/td&gt;
                              &lt;td&gt;john@example.com&lt;/td&gt;
                              &lt;td&gt;john@example.com&lt;/td&gt;
                              &lt;td&gt;John&lt;/td&gt;
                              &lt;td&gt;Doe&lt;/td&gt;
                              &lt;td&gt;john@example.com&lt;/td&gt;
                          &lt;/tr&gt;
                      &lt;/tbody&gt;
                  &lt;/table&gt;
              &lt;/div&gt;
          &lt;/div&gt;
      &lt;/div&gt;
  &lt;/div&gt;
  </code></pre>
  
  <p>any angularJS expert here? help required!</p>
  
  <p>onclick of each button,i am trying to fill the array with new values!  but it seems to not happen! am i doing something wrong?</p>
  
  <p>i tried to declare thhe array again in each of the functions so that the old values get flushed out! </p>
  
  <p>any help or advice and changes are appreciated!</p>
  
  <p>here is the result:
  <a href="https://i.stack.imgur.com/WkPMZ.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/WkPMZ.png" alt="result"></a></p>