I'm having trouble getting a particular Angularjs filtering setup working that involves a text input, ng-repeat and a select, and love any assistance anyone can provide.
I have an array of objects like so:
[{ id: '1', firstName: 'Charles', lastName: 'Charlston' }, ...]
I'm filtering the array by text input like so:
<input ng-model="searchText" />
<div ng-repeat="person in people | filter : searchText" ...
Currently, this sorts the array of people objects for "any" property value and it works fine.
What i'm trying to achieve is be able to change the property that my <input ng-model="searchText" />
filters the people array by, based on what <option id="1" label="lastName" selected>Last Name</option>
is selected.
My select looks like this:
<select class="filterSelect"
ng-model="selectedPropertyOption"
ng-options="prop.name for prop in peopleProperties"></select>
peopleProperties looks like this:
$scope.peopleProperties = [{id: "1", name: "firstName"}, ...];
So instead of typing: "charles" in the input and getting results that match either property id, fistName or lastName, I need to be able to choose an option from a select where the option is a property name like "firstName", that I want to filter by. Then, whatever is typed in the input would only filter objects based on which option was selected.
I hope this makes sense enough! Any guidance would be much appreciated, thank you in advance!