Filtering a Firebase list by another Firebase Object in Angularjs
-
21-12-2019 - |
Question
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!
Solution
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.
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow