Using the outer ng-repeat's object property to filter nested ng-repeat items

I'm currently working on nesting two ng-repeats with two separate JSON files. The goal is to filter the second ng-repeat based on parameters from the first ng-repeat.

The first JSON file, $scope.matches, includes information about each match in the World Cup. The second JSON file, @scope.predictions, contains predictions made by users for each game.

My objective is to display a match as a header and then list all corresponding predictions underneath it. This process should be repeated for every match until all predictions are displayed accurately. I need to ensure that match.matchnumber equals prediction.matchnumber.

In my Plunker http://plnkr.co/edit/GQmYxZiO53nkIBVczaS9?p=preview, you can observe that the filter isn't functioning correctly because it's being applied to all object parameters instead of just matchnumber.

What would be the simplest approach to resolve this issue? Should I merge the JSONs into a filtered array? If so, what would be the most efficient method?

Answer №1

To filter results based on a specific property, you can utilize an object with the property name as the key and the search term as the value:

ng-repeat="p in predictions | filter:{matchnumber: match.matchnumber}"

This filter will only display predictions where the matchnumber property matches match.matchnumber.


You can also check out this recent demonstration.


It may not be very efficient to iterate through all predictions for each match in every iteration. A more optimal approach would involve processing both JSON files and creating a third one that contains all necessary data, eliminating the need for filtering in the view.

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

Click on every link to reveal a hidden div

When I click on and select the first link in the mainPart, I want to automatically select the first subLink div in the secondPart while hiding the other subLink classes. This sequence should be maintained: when the second link is selected, the second sub ...

Is there a way to circumvent the mouse up event?

I want to create a feature where when a user clicks down, something specific occurs. The sequence of events includes: An action taking place (which is not the focus here). Triggering a mouse up event. Implemented with: angular, html, css. Excludes: jQue ...

A guide on implementing the MVC architecture in a web application with Node.js, Express, and PostgreSQL

I'm struggling with implementing the MVC architecture in my node web app, specifically when it comes to separating the model from the controller. Currently, I have the views properly organized (all my .ejs files) and I consider my app.js as the contr ...

Currently focused on developing vertical sliders that can be manipulated by dragging them up or down independently

https://i.stack.imgur.com/NgOKs.jpg# I am currently working on vertical sliders that require dragging up and down individually. However, when I pull on the first slider, all sliders move together. The resetAllSliders button should also work independently, ...

How can AJAX be utilized to show search results dynamically?

At the moment, I have a PHP page that pulls a list of results from my SQL database and displays the ID and names. There is a search bar at the top where you can search for keywords in the "name" field, and when you click on search, it takes you to a new p ...

Utilize SVGs efficiently by loading them once and reusing them

Is it possible to use the same SVG element twice on a web page without having to load it again? I am changing the CSS of the SVG using JavaScript, so I believe the SVG must be directly embedded in the HTML rather than included as an object. Both instance ...

Using a subheader in conjunction with a virtual repeater in markdown does not function correctly

Currently, I am utilizing angular 1 along with angular material. I am trying to incorporate md-subheader with multiple md-virtual-repeat-containers within an ng-repeat loop. The source code can be found on this codepen. The issue I am facing is slightly c ...

`Utilizing the Data Returned by Promises in AngularJS $http Service`

How do I extract the value from the Promise returned by the $http service? >d {$$state: Object} $$state: Object status: 1 value: Array[1] __proto__: Object __proto__: Object What is the procedure to access the value in the d object? s.states = & ...

Click events are unresponsive when used within ng-repeat

Having trouble with ng-click inside of ng-repeat. It seems to work fine outside of it. Check out this JSFiddle link <div ng-controller="MyCtrl"> <a ng-click="triggerTitle='This works!'">test</a> <h5>Please select tri ...

Tips on improving image loading speed in JavaScript code

I'm working on a simple weather map that changes the background image depending on the current weather status. However, I've noticed that there is a delay in changing the image when the weather status changes. I'm wondering if this delay is ...

Using PHP, jQuery, and HTML to submit a form and insert data into MySQL, all while

I am facing an issue with my PHP intranet site, which includes an HTML form with 2 input fields. My goal is to take the user's input from the form and insert it into a MySQL database without redirecting the user to another page. I have a separate PHP ...

Guide to dynamically incorporating items from an array into the filter operation

How can I dynamically insert items from an array into the filter on the wizard.html page, so that when the templateUrl in the route is called, it can be rendered on the wizard.html page? Controller angular.module('tareasApp') .controller(&apo ...

Missing Angular reference in WordPress

Have you ever tried integrating Angular into a WordPress plugin? I recently attempted to do so by adding the following code: wp_register_script('jquery-custom', ("http://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"), false); ...

What is the best way to combine two JavaScript objects?

One object I am currently working with resembles the following structure let ob1 = { 'item_data':{ 'stack':{ 'purchase':'12345', 'order':'22222' } } } Additionally, I have anothe ...

Having trouble retrieving data values from methods within my Vue.js component

I am having trouble accessing the lat and lng values from the data() method within the maps() method. Here is a link to my Vue.js component code: https://gist.github.com/melvin2016/c8082e27b9c50964dcc742ecff853080 Here is an image of the console showing ...

Populate HTML form with return values using jQuery AJAX

I am struggling with retrieving values from jQuery/AJAX and displaying them in an HTML form within the index.php file. This is what my index.php looks like: <script type="text/javascript"> $(document).ready(function () { $('#display'). ...

Uploading multipart/form-data files in Angular with the $http module

I've encountered an issue that I need help with - despite the abundance of similar questions. Here's my problem: My goal is to transfer a file from an input field to a server using multipart/form-data I've attempted two different methods. ...

Is it possible to initialize the ng-model's value using other values within the scope?

I am attempting to calculate the product of two values entered by the user and then assign that result as the ng-model for a third value. However, I am having trouble getting this code to function properly. <input type="number" ng-model="a"> <inp ...

What is the purpose of returning a function in a React Hook?

Currently, I am incorporating Material-UI components into my project and have implemented the AutoComplete component in my application. While exploring an example provided by the Material-UI team, I stumbled upon a fascinating instance of using Ajax data ...

If the variable is defined within $scope, ng-model-options will not be taken into account

In my current project, I am utilizing the AngularJS Bootstrap Datepicker (also known as uib-datepicker). My goal is to set a specific UTC offset on it, which can be achieved by setting the ngModelOptions like this: ng-model-options="{timezone: '+02:00 ...