Filtering an array in AngularJS based on a property that is an array data type

I am trying to filter my $scope.contracts based on the partner's name in HTML. My object structure is as follows:

$scope.contracts = [
 {
  name: "contract1",
  partners : [{name: "John", age:"21"}, {name: "Peter", age: "33"}]
 },
 {
  name: "contract2",
  partners : [{name: "George", age:"51"}, {name: "Jack", age: "42"}]
 }
];

My filtering code looks like this:

ng-repeat="contract in contracts | filter : {partner: {name: 'John'}}"
. However, despite expecting to retrieve the first contract where the partner's name is 'John', I'm receiving an empty array instead.

Answer №1

A mistake in the code, it should say partners instead of partner inside the filter.

ng-repeat="contract in contracts | filter : {partners: {name: 'John'}}"

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

Having trouble with the parent folder functionality in JavaScript?

I am facing a challenge with my website's structure as I have an old setup that needs to be updated. http://localhost/enc/pdfs/ : This directory contains some html files that are uploaded via ajax to be displayed on a tabbed div using: var Tabs ...

Conceal the name of a property when displaying it

I have a function that retrieves data from an interface, which includes a property called name. Currently, the output includes the property name, but I would like to remove it if possible. How can I achieve this? Here is the interface structure: export i ...

Using jQuery to retrieve child elements and assign numerical values to them

Looking for a jQuery function that can apply different CSS attributes to children elements of a div. <div class="container"> <div class="autogenerated-div"></div> <div class="autogenerated-div"></div> <div class="aut ...

Vue watchers capturing original value prior to any updates

When working with Vue.js, we can easily access the value after modification within watchers using the following syntax: watch: function(valueAfterModification){ // ...... } But what about getting the value before it's modified? PS: The official ...

Encountering a registration error persistently: [TypeError: Network request failed]

Currently, I am in the process of developing an application using React for the frontend and node.js for the backend. However, I have encountered a persistent network error whenever I try to sign up or log in. What puzzles me is that when I test the API en ...

Guide on transferring value from a <select> element using JavaScript

I'm attempting to pass the selected value of a <select> in the onChange function. I've explored this question on SO, but unfortunately, using this and this.value hasn't been successful. I understand that the question is quite old... se ...

React Native - Implementing a dynamic form that adapts based on the answer given by its parent

My JavaScript Object has a simple state structure as follows: pertanyaan: [{ label: "label1", type: 'dropdown', key: 'keyFoo1', option: [{ value: "foo1" }, { value: "foo2", additional ...

Angular 1.6 limits the ability to include multiple custom components on a single page

I'm currently working with angular 1.6 and have encountered an issue with two components, config-list and request-dates. Both components function correctly individually on a page, but when I attempt to add both components to the same page, only the s ...

When downloading files in Chrome or Safari, the $ajax call is in a pending state, whereas in IE or Firefox,

Measuring the time it takes to download a 1MB file using AJAX calls. Below is the code snippet: var start = new Date(); $(document).ready(function() { $.ajax ({ url: 'https://www.example.com/dummyFile1024', crossDomain: t ...

Tips for turning off the auto save password option on browsers for user registration forms

Is there a way to prevent browsers from saving passwords on the add users form? I've tried using autocomplete="off" but it doesn't seem to work for saved passwords. I've searched extensively for a solution but haven't found the right on ...

Difficulty arising from implementing v-if as a filter within a v-for loop in Vue.js

I'm struggling a bit with setting up a conditional statement using v-if along with a loop using v-for in Vue. Here's what I have so far: <div class="row form-group" v-for="(article, key, index) in articles" :key="key" v-if="article.pubdate(fi ...

The implementation of automatic meta tag generation functionality in Wordpress is experiencing some technical glitches and is not functioning

I am in need of a solution to automatically generate meta tags from content in Wordpress. The issue lies in the code I have come across on various blogs during my search, as it either uses $des_post = str_replace( array( "\\n", "&b ...

Node.js woes: troubleshooting object output issues

I am currently delving into the world of Node.js and express as I explore building a simple bike configuration. I have created an object that encompasses all the necessary properties for this project. After exporting this object, I attempted to display it ...

Use Javascript to create commands and variables specific to the domain or site of a webpage

Currently, I have implemented the code below to fetch the latest tweet. However, I am looking for a way to customize the TWITTERUSERNAME based on the domain where the template is being used. This template is shared across multiple domains. <script type ...

Creating custom functions in jQuery and utilizing them within other functions

I have a specific piece of code that I need to execute in two different locations, so I am considering placing it inside a function and calling that function in both places. However, I'm unsure of how to achieve this using jQuery: Could anyone provi ...

Javascript Function : Toggle visibility of div when user clicks anywhere on the page

I have implemented a feature where clicking on the 3 dots reveals a div, and clicking again hides it. However, I would like the div to hide when clicking anywhere else on the document. Imagine two circles - clicking on one circle displays a div, while cli ...

Using Three.js: Adjust the UV coordinates of my texture within a specialized ShaderMaterial

Currently, I am working with a plane geometry and developing a CustomShader material for it. This material will require some textures as uniforms and I want these textures to completely cover my plane (similar to the background-size:cover CSS property). P ...

Troubleshooting issue: Unable to remove objects from an array using Vue.js

Having trouble with a Vue.js project where I'm attempting to delete an object from the items array by clicking the remove button in the CheckList.vue file. However, I keep encountering this error message: Property or method "remove" is not defined on ...

Is it possible for jQuery to detect if an email was sent from the client's email account?

I am working towards a feature on my website where users fill out specific fields and then click "send email" to activate their email platform via "mailTo", with the email pre-populated for easy sending. The challenge lies in confirming if the user actuall ...

The for loop is decrementing the value instead of incrementing it

Hi there, I'm a beginner in JavaScript and I've been experimenting with it. Today, I encountered a problem that I need help with. The code may seem messy but my goal here is to remove items from idList that are not found in onlinelike. However, ...