hyperN
hyperN

Reputation: 2754

Angular filtering doesn't work

In my template I have this code:

 <li class="row timeline-item" data-ng-repeat="item in data | filter:workoutFilter" data-ng-include="getTemplateUrl(item)"></li>

And in my controller I have:

   $scope.workoutFilter = null;
  $rootScope.$on('workout', function(e, data) {
        $scope.workoutFilter = "{Type: 'workout'}";
    });

When I click button workouts, everything just disappears as if there are no items that match this filter, but that isn't the case (and I know this for a fact because getTemplateUrl detects type workout and returns right template)

Why is this happening ? Is there any other way I can filter items which have property Type "workout" ?

EDIT

Here is what happens when I click button:

In my other controller :

$scope.onWorkoutsClick = function () {
    feedService.setWorkoutFilter();
};

In service:

setWorkoutFilter : function() {
        $rootScope.$broadcast('workout');
    }

And in my main controller:

$rootScope.$on('workout', function(e, data) {
        $scope.workoutFilter = "{Type: 'workout'}";
    });

Upvotes: 0

Views: 506

Answers (1)

Stepan Riha
Stepan Riha

Reputation: 1724

I assume you're trying to filter based on item.Type == 'workout'?

You need to set your filter to an object rather than a string:

$scope.workoutFilter = {Type: 'workout'};

Upvotes: 2

Related Questions