-1

I have a scope varible containing an array of articles (JSON objects)

$scope.mainArticles = [];

An article has these properties

{
 "title": "ABCD",
 "type": "XYZ" 
}

I Filter the scope variable $scope.mainArticles based on article type, using the filter method of JS.

$scope.mainArticles = $scope.mainArticles.filter(filterByTypeFunction);

But my DOM never updates even though the scope variable has changed. Is there any way I can avoid using $scope.$digest() or $scope.$apply() in this scenario?

I don't wanna use them since there are plenty of answers here which advises against using them.

Community
  • 1
  • 1
Giridhar Karnik
  • 2,213
  • 4
  • 27
  • 47

1 Answers1

-1

better way it is to filter you articles on the server You don't want to load all your articles at once and then filter it

neuronet
  • 1,139
  • 8
  • 19
  • Actually I need to load all the articles up front, since by default there is no filter. So once I have all the articles on the client side, why not just filter it? – Giridhar Karnik Jul 20 '16 at 17:58
  • if You don't have pagination then it will be ok but with pagination your filter on the client side will be working weird because you will be filtering only one page – neuronet Jul 20 '16 at 18:06
  • no matter if there is a filter or will be if user selects it, load your documents filtered (or not) and paginated from the server side, if you will have a lot of articles you will have troubles like getaways timeouts and so on – neuronet Jul 20 '16 at 18:12