0

I'm trying to do a filter on angular, it's working if I just do a ng-repeat but when I try this code:

<div class="row" ng-repeat="article in articles track by $index" ng-if="$index % 3 == 0">
  <div class="col-md-4" ng-repeat="i in [$index, $index + 1, $index + 2] | filterByType:typeOfPost" ng-if="articles[i] != null">
    <div class="thumbnail">
      <p><img class="pageImage" ng-src="{{articles[i].pageImage}}"></p>
    </div>
  </div>
</div>

it removes all the data.

I'm not sure how to set this filter in order to get the columns filtered by the post type.

Basically what I have is this:

Dropdown button > Sort by photo / author

X X X X X X X X X

(X is an article)

However, right now it's not filtering it correctly

(I'm also using bootstrap)

Not a duplicate: I can pass the values, the articles are showing, what I can't do is filter them correctly since they are inside a ng-repeat. Usually I'd just do {{article.pageImage}} with the filter in ng-repeat="article in articles", but here it's not working

Xero Kael
  • 132
  • 1
  • 12

1 Answers1

0

Ended up filtering the information inside the controller as per Amit's suggestions in the comments:

$scope.setTypePost = function(post) {
    $scope.typeOfPost = post;
    if (post === 'all') {
        $scope.articles = $scope.articles2;
    } else {
        $scope.articles = $filter('filter')($scope.articles2, {typeOfPost:$scope.typeOfPost}, true);
    }

}
Xero Kael
  • 132
  • 1
  • 12