Having trouble with filtering JSON data in AngularJS?

I'm sorry if this question has already been answered. I tried looking for solutions on other websites, but couldn't understand them. I am attempting to filter JSON data within the ng-repeat function, but whenever I try to input something, it doesn't display anything. Any help or direction would be greatly appreciated. You can see an example of what I mean in this jsbin:

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

Answer №1

To adjust your filter criteria, use the following method:

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

This will specifically search for the search term within the title.$text property.

Remember to initialize your searchquery as empty in the controller:

$scope.searchquery = '';

Check out the updated Jsbin here: http://jsbin.com/AQoJEMU/1/edit

Answer №2

One issue is that the filter is unable to access nested properties.

It is unable to filter stories.title.$text.

Possible solutions:

  • Create your own custom filtering function.
  • Find a way to expose the content to be filtered in a property that is not nested. For example, instead of stories.title.$text, make it accessible as stories.title_text.

Check out this functional JS Bin: http://jsbin.com/esAteYI/2/edit

I have made two adjustments:

  1. Established a stories.$text property that includes the contents of both stories.title.$text and stories.teaser.$text.

  2. You can specify the property on which the filtering should be carried out. Take note of how I modified the ng-model attribute of the search input field to

    <input ng-model="searchquery.$text" />

    By specifying the .$text property, the filter will focus only on it, saving time and avoiding unnecessary checks on other properties.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

When using google search with json_decode, the result returned is null

$query = "Poultry meat is a major source of animal protein considering"; function fetch_google($query) { $cleanQuery = str_replace(" ","+",$query); $url = 'http://www.google.com/search?q='.urlencode($cleanQuery); $data=file_get_contents($url ...

Issue with Empty Date Time Format in Vue2 Date-Picker

In our company, we use vue2-datepicker to manage the starting and ending times of meetings. The dates are stored in "YYYY-MM-DD HH:mm" format on the backend, but we convert them to "DD-MM-YYYY HH:mm" format when retrieving the data in the mounted() hook. T ...

What is the best way to "re-upload" drop-down selection using javascript?

I am attempting to automate a drop-down selection process on a website using a headless browser called Firefox Marionette. The website is not under my control, and the process involves: A primary drop-down menu where I can choose an option. A secondary dr ...

What is the best way to loop through a group of WebElements, and only log the results that contain a specific substring?

In my test case, I'm utilizing Mocha to handle the scenario. The test appears to be passing successfully, however, no logs are being printed... it('Is 'Mooooooo!!!! I2MaC0W' a Substring in Results?', function() { this.timeout(50 ...

Are Lazily Instantiated Singletons a Thing in AngularJS?

After browsing through the AngularJS documentation, I came across an interesting detail about AngularJS services: AngularJS lazily instantiates services, meaning they are only created when a component in the application requires it. Services in AngularJ ...

The promise from the angular $http function is being duplicated

As I work on evaluating an expression within an if statement to return either true or false, I am utilizing $http promises. Despite the abundance of documentation available on this topic, I am confident in my ability to resolve any issues that may arise. ...

Exploring methods for testing an HTML page that utilizes jQuery for DOM manipulations

Recently, I was tasked with creating an HTML page that utilized jQuery DOM manipulations. For instance, upon clicking the submit button, a success or error message should be displayed. Testing these functionalities is something I'm familiar with in An ...

When attempting to upload a jsonArray to php, I encountered an issue where I received an error stating that the org.json.JsonArray

I am encountering an issue while attempting to send a jsonArray to a PHP server. The error message states: "Error while posting org.json.JSONArray cannot be converted to JSON Object." Please inform me about what might be causing this problem. Here is the ...

The Javascript calculation function fails to execute proper calculations

I have been facing immense frustration while working on a project lately. The project involves creating a unique Webpage that can calculate the total cost for users based on their selections of radio buttons and check boxes. Assuming that all other functi ...

AngularJS: Functions may return false due to the asynchronous nature of services

Template Overview: <div data-ng-if="budgetSummaryExists()"> <span>You currently have no budget.</span> <button type="button" class="btn btn-danger" data-ng-click="setRoute('budgets')">Creat ...

Is there a way to modify the value of a constructor key once it has already been defined?

I am currently working on a simple constructor exercise where I need to update a value after the constructor has been created. Even after changing the value to true, the cat is still not making its noise. Challenge parameters The constructor function wi ...

Steps for choosing all choices in a multi-select menu without changing the order

What is the best way to choose all the options from a multiselect box using Java Script? ...

Enhancing jQuery Mobile listview with voting buttons on each item row

I am looking to incorporate 2 vote buttons within a jQuery mobile listview, positioned on the left-hand side and centered within each list item. While I have managed to achieve this using javascript, my goal is to accomplish it without any additional scrip ...

How can Tweepy be utilized to extract the integer count and incorporate it?

Hope all is well with everyone here. My apologies if this question has been addressed previously, but I am currently working on the following task. cursor = tweepy.Cursor( api.search_tweets, q = '"Hello"', lang = 'en&ap ...

Coloring a table in vue.js based on performance rankings

I'm facing an issue with sorting my data performance in vue js. Here is the script I have created so far: <template> <div> <div class="row"> <h2> Campaign Performance </h2> <table class=&q ...

Setting up Angular-CLI on a Windows 10 system

I encountered some challenges while trying to install angular-cli on my Windows 10 system. The issues revolved around Python dependencies and node-gyp, manifesting in error messages similar to the following: ><a href="/cdn-cgi/l/email-protection" ...

Ways to update a div periodically with new data fetched from a file - Here's How!

I am looking to auto-refresh a specific div every few seconds on my index.php page below. <?php session_start(); if (! check_write()) { redirect('testlogin.php'); return; } if (file_exists('lmt.json')) { $lmt = json_de ...

Avoid potential issues caused by cancelled asynchronous requests affecting the application's status by using the watchEffect() function

Imagine a scenario where a component receives the ID of a resource through a prop called resourceId. This component is responsible for fetching the corresponding resource from an API and displaying it, while also managing loading and error states (similar ...

The React getTime() method does not properly update the state

I am attempting to update the state of the component Demoss using an external function called getTime(). My goal is to start updating the time in the state time when the page loads. In order to achieve this, I have called it in the componentDidMount meth ...

How can I ensure that VueJS only starts loading data after the initial API call has been completed?

After retrieving data from an API, I populate a form in my component. The challenge I am facing is that the watchers are triggered immediately after populating the initial data. I want them to be triggered asynchronously. Additionally, I need to prevent th ...