1

I apologize if this has been answered beforehand I searched but couldn't understand the answers on other stack overflows so if they did have the answer I couldnt make sense of it. I am trying to filter the JSON data that is in the ng-repeat but it just brings up nothing whenever I type something into the input. Just a bit of help even if its just pointing me in the direction would be greatly appreciated. I have a jsbin that shows what I am talking about.

http://jsbin.com/ILEQEso/1/edit

2 Answers 2

1

You can modify your filter criteria like this:

ng-repeat="story in storytitle | filter:{'title.$text':searchquery}"

It will look for the search term on the title.$text property only.

Don't forget to set your searchquery to empty at the beginning in the controller:

$scope.searchquery = '';

Here is your updated Jsbin: http://jsbin.com/AQoJEMU/1/edit

Sign up to request clarification or add additional context in comments.

Comments

0

The problem is that the filter can't reach nested properties.

It can't filter stories.title.$text.

Possible solutions:

  • Write your own filtering function.
  • Somehow make the contents to be filtered available in a property which is not nested. For example: instead of stories.title.$text, make it available at stories.title_text.

Here is a working JS Bin: http://jsbin.com/esAteYI/2/edit

I have done two things:

  1. Created a stories.$text property, including the contents of both stories.title.$text and stories.teaser.$text on it.

  2. You can specify to which property tthe filtering should be applied. Look how I've changed the ng-model attribute of the search input field to <input ng-model="searchquery.$text" />
    By specifying the .$text property, the filter will work only on it. So, it will not waste precious time trying to apply the search through the other properties.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.