Im trying to remove an md-item
in suggestion when the user selected an item and is marked as favorite. To clarify the question here is the structure below.
Supposing that we have this structure of states
.
function loadAll() {
var allStates = [
{
display : Alabama,
value : alabama,
is_favorite : false
},
{
display : Alaska,
value : alaska,
is_favorite : false
},
{
display : California,
value : california,
is_favorite : false
},
{
display : Colorado,
value : colorado,
is_favorite : false
},
{
display : Florida,
value : florida,
is_favorite : false
},
{
display : Georgia,
value : georgia,
is_favorite : false
},
];
return allStates;
}
This is what i did for marking the state as favorite when the user selected the object i put it on the function md-selected-item-change
.
function selectedItemChange(object) {
if (object) {
object.is_favorite = true;
}
}
Now it is possible to alter the createFilterFor()
to exclude from the results the states which has is_favorite == true
after selecting a particular state?
function createFilterFor(query) {
var lowercaseQuery = angular.lowercase(query);
return function filterFn(state) {
return (state.value.indexOf(lowercaseQuery) === 0);
};
}
This is what ive'd tried so far but it doesn't render the correct result.
return (state.value.indexOf(lowercaseQuery) === 0 && state.is_favorite == false);
UPDATE
There is a simple fix for this:
All you have to do is to put the filter in the source for your control.
Please check the code pen : http://codepen.io/ash972/pen/ZLYNPM