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);
1

2 Answers 2

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);
Sign up to request clarification or add additional context in comments.

1 Comment

@T.J.Crowder it returns all elements which match the criteria in an array.
0

Okay, asked my question to quickly.

This is how I did it

$scope.selectedActivity = $filter('filter')($scope.activityTypes, { activityType: $scope.activityType} );

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.