1

I have an array of objects, and in the object I have an element {url:"that happens to have the word search in it"} , so when filtering if you type "arch", this link field doesn't allow for filtering as one would expect for the rest of objects.

It's a pretty big object and I would like to search all of it, I just want to exclude the url element. I can't remove it, as it pertains to a link used in the ng-repeat. I also have a location search that I probably need to reevaluate in order to create a filter function that handles both.

Any help would much appreciated thanks.

Heres a Plunker

Dylan
  • 4,703
  • 1
  • 20
  • 23
  • 1
    `$watch` inside an Angular controller is a code smell. Prefer filtering instead - http://plnkr.co/edit/zcGhOzxRfjUADKQGICFH?p=preview – miqh Apr 09 '15 at 02:29

1 Answers1

1

You can create a searchFilter in your controller. Put this in your html:

<input name="searchText" type="text" class="form-control" placeholder="Search" ng-model="vm.searchText">

Put this in your controller:

vm.searchFilter = function (obj) {
    var re = new RegExp(vm.searchText, 'i');
    return !vm.searchText || re.test(obj.title) || re.test(obj.city);
};

Then this on your ng-repeat:

<tr ng-repeat="items in vm.myitems | filter:vm.searchFilter">
JohnWrensby
  • 2,652
  • 1
  • 18
  • 18