0

So i have a big firebase list that I want to filter using another firebase object that I am binding to. If I do not bind my 'search' object to firebase it filters just fine, but when i do bind to Firebase it returns zero results.

my controller:

  .controller('TestResultsCtrl', ['$scope', 'syncData', '$routeParams', '$firebase', '$filter', function($scope, syncData, $routeParams, $firebase, $filter) {
      $scope.id = $routeParams.id;
      syncData('tests/' + $routeParams.id).$bind($scope, 'test');
      syncData('tests/' + $routeParams.id + '/specs').$bind($scope, 'search');
      syncData('diagnoses').$bind($scope, 'all_diagnoses');
   }])

my view:

<a href="" ng-repeat="diagnoses in all_diagnoses | orderByPriority | filter:search" class="list-group-item">{{diagnoses.title}}</a>

a sample 'search' object:

{
  "constant": true,
  "intermittent": true,
  "localized": true,
  "referred": false,
  "region": "hip"
}

a sample of the 'diagnoses' firebase object/list:

{
  "constant": true,
  "intermittent": true,
  "localized": true,
  "referred": false,
  "region": "hip",
  "title": "Hip Osteoarthritis"
},
{
  "constant": true,
  "intermittent": false,
  "localized": false,
  "referred": true,
  "region": "neck",
  "title": "Whiplash"
}

How do I get this to filter correctly?
...and thank you in advance!

1 Answer 1

2

The issue probably is that the object returned from $bind contains several $ methods which Angular is trying to filter against.

Try something like this...

syncData('tests/' + $routeParams.id + '/specs').$bind($scope, 'searchDirty');
$scope.$watch('searchDirty', function (search) {
    $scope.search = angular.fromJson(angular.toJson(search));
});

This will strip out any $ methods/values and return the raw value of the data.

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

Comments

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.