I'm attempting to use the $filter function in my controller, within a $watch function, to filter specific fields. I am having trouble understanding the documentation provided.
The situation: I have a dropdown menu that serves as the filter parameter. I intend to filter an array called $scope.images based on a particular field named Vessel. When an option is chosen from the dropdown list, the $watch function should filter the array accordingly.
Currently, the code I have filters on all fields rather than just the specified one.
Angular Code:
$scope.$watch('search', function(val)
{
$scope.images = $filter('filter')($scope.items2, val);
}
View
<div ng-app="masterApp" ng-controller="listCtrl">
<div class="container">
<label for="singleSelect"> Select Vessel: </label><br>
<select name="singleSelect" ng-model="search">
<option value="African Chaser">African Chaser</option>
<option value="African Sprinter">African Sprinter</option>
</select>
<h3 class="text-center">Time: {{images[slider.value].Created | date:'medium'}}</h3>
<img src="https://intra.monjasa.com/{{images[slider.value].File.ServerRelativeUrl}}" class="feed_image">
<rzslider rz-slider-model="slider.value" rz-slider-options="slider.options"></rzslider>
</div>
</div>
What I have tried:
$scope.$watch('search', function(val)
{
$scope.images = $filter('filter: Vessel')($scope.items2, val);
}
The above code snippet is not yielding the desired result.
Can anyone provide any insights into where I might be making a mistake?