I would like to filter an employee object array using $filter('filter') to filter the results based on an employee's first name field ONLY that can be selected from the drop down/select. Notes that I do NOT want to use the "| filter:" in the ng-repeat".
The difficulty is that the name field is a property of another field called 'details', so I can't details.name like the code below because it will error.
$scope.filteredEmployees = $filter('filter')(employees, {details.name: selectedName });
See below for structure of the employee array object.
How can I tell it to filter the records based on details.name field using $filter('filter')?
Thank you in advance for your help!
Here is the code:
Var selectedName = “An”;
$scope.filteredEmployees = $filter('filter')(employees, {**details.name:** selectedName });
Var employees = [
{
Date: 01/01/2012
details: {
name: ‘An’,
age: 25
}
},
{
Date: 01/01/2012
details: {
name: ‘'Bill',
age: 20
}
}];
//Here is
<select ng-model="selectedName" ng-options="e for e in employees" data-ng-show="employees.length > 0" ng-change="filterEmployees">
<option value="">All Employees</option>
</select><br>
function filterEmployees() {
$scope.filteredEmployees = $filter('filter')(employees, "Joe");
};