ajaxdinesh
ajaxdinesh

Reputation: 1

Filter Records - Angular JS and FireBase

I am currently working basic angular app and database using firebase. My Question is, How to filter the records in angular once loaded all the datas from firebase. I used to find many ways in Google. Finally, i got a solutions using OrderByPriority (Object to Array). Its working fine but the problem is, I got some error when i edited the existing records. I got this below error when i edit the records when i used the OrderByPriority.

**Error:** Firebase.set failed: First argument contains undefined

Code:

data-ng-repeat="(key,person) in contactList | orderByPriority | filter:searchCategory

My Apps Screen part - I have given left navigation part only,

Category
All        (5)
Family     (2)
Friends    (3)

My Questions are,

  1. How do i filter the data when i click the cateogry(Eg., All, Family, Friends etc.,) and display the records accordingly based on the selection?
  2. Also I need to count the records for 'All' Category.

I am waiting for your favorable reply. Thanks for advance.

Upvotes: 0

Views: 170

Answers (1)

Kato
Kato

Reputation: 40582

  1. How do i filter the data when i click the cateogry(Eg., All, Family, Friends etc.,) and display the records accordingly based on the selection?

You will want your person records to have a category field. Then when a category is clicked, simply put it into $scope.searchCategory:

All ({{counts['all']}}) Family ({{counts['family']}})

  1. Also I need to count the records for 'All' Category.

Isn't this simply the total of the others?

Total: {{ counts['family'] + counts['friends'] }}

Or with a method in your controller:

$scope.totalCount = function() {
  var total = 0;
  angular.forEach(counts, function(x) { total += x; });
  return total;
}

Upvotes: 1

Related Questions