0

I have an array of objects. Each object has multiple properties such as 'activityType'. I'm trying to assign that object to $scope.selectedActivity based on the $scope.activityType value that is already assigned. I've tried to use $filter but I'm not sure how to code the expression properly.

This is my code:

$scope.selectedActivity = $filter('filter')($scope.activityTypes, $scope.activityTypes.activityType == $scope.activityType);
LazioTibijczyk
  • 1,701
  • 21
  • 48
  • Possible duplicate of [How to use a filter in a controller?](https://stackoverflow.com/questions/14302267/how-to-use-a-filter-in-a-controller) – T.J. Crowder Apr 09 '18 at 12:06

2 Answers2

1

Try this. Give an object for comparision and set to strict (true). Read $filter for more informations.

$scope.selectedActivity = $filter ('filter')($scope.activityTypes, { 'activityType': $scope.activityType }, true);
wayneOS
  • 1,427
  • 1
  • 14
  • 20
0

Okay, asked my question to quickly.

This is how I did it

$scope.selectedActivity = $filter('filter')($scope.activityTypes, { activityType: $scope.activityType} );
LazioTibijczyk
  • 1,701
  • 21
  • 48