1

I have a ng-repeat with two filters. When i update one "uniqueFilter" via a button, the list does not update with my new filter. Here's the HTML

  <div ng-controller="FooterController" class="bar bar-footer">
    <button class="button button-clear" ng-click="switchViewType('LOCATIONS')">Locations</button>
    <button class="button button-clear" ng-click="switchViewType('DEPARTMENTS')">Right</button>
    <button class="button button-clear" ng-click="switchViewType('CENTERS')">update</button>
  </div>

  <div class="list list-inset has-subheader-sbm"> 
    <label class="item item-input">
      <i class="icon ion-search placeholder-icon"></i>
      <input type="search" ng-model="query" placeholder="Search">
    </label>
  </div>

  <ion-content ng-controller="ListController" class="has-subheader-search-sbm">
    <ion-list>
        <a class='item item-icon-right' ng-repeat="item in directory | filter : type=uniqueFilter | filter : query" href="tel:{{item.phone}}">
          {{item.label1}}<br>
          {{item.label2}}
         <i class="icon ion-ios-information-outline"></i>
      </a>
    </ion-list>   
 </ion-content>

Here is my app.js code

appCtrl.controller('ListController', function($scope, $http) {

  var url =   'https://server/Ataglanceservice.svc/getDAAG';

  $http.get(url).then(function(resp) {

    // For JSON responses, resp.data contains the result
    $scope.data = resp.data
    $scope.directory = angular.fromJson($scope.data);
  }, function(err) {
   console.error('ERR', err);
  })

 $scope.uniqueFilter = 'DEPARTMENTS';
 //$scope.varView = 'LOCATIONS';

});

appCtrl.controller("FooterController", function($scope, $localStorage) {


$scope.switchViewType = function($viewType) {
  $scope.uniqueFilter = $viewType;
}

}); 

Can anyone tell me why my filtered list is not being updated?

thanks.

1 Answer 1

1

The scopes are different in each controller, each $scope.uniqueFilter point to different locations. A simple way to fix this is merge the controllers and just use 1 controller if possible, or make use of angular services (https://docs.angularjs.org/guide/services), having the variable as a part of a service so it may be used across different controllers.

Sign up to request clarification or add additional context in comments.

1 Comment

ok, I got it working! I thought scope was available globally. thanks for your help!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.