Ways to enable selective searching for object data in AngularJS

Imagine having an object like this:

"results" : [
      {
         "Item.ad_title" : "Test Phone",
         "System.id" : "29183546",
         "Transaction.price" : "700.00",
         "Owner.phone_number" : "22225987",
         "Publication" : {
            "publication_text" : "bla bla bla "
         },
         "Item.id" : "142",
         "Owner.email" : "<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="e48189858d88a48189855b79">[email protected]</a>",
         "Item.tags" : [
            "tag1",
            "tag2",
            "teg3"
         ]           
      },
]

Next, picture a text input with ng-model="search" and a

ng-repeat="product in products | filter: search"
.

While this setup allows searching through all data, there may be cases where you want to limit the search to specific fields like Item.ad_title, publication.publication_text, Transaction.price, and Item.tags.

Is there a way to instruct Angular to focus the search on these particular fields only?

Edit: The goal is for this to be achieved using a single search input field.

Answer №1

If you refer to the Angular documentation, you'll find the following code snippet:

<label>Any: <input ng-model="search.$"></label> <br>
<label>Name only <input ng-model="search.name"></label><br>
<label>Phone only <input ng-model="search.phone"></label><br>
<label>Equality <input type="checkbox" ng-model="strict"></label><br>
<table id="searchObjResults">
  <tr><th>Name</th><th>Phone</th></tr>
  <tr ng-repeat="friendObj in friends | filter:search:strict">
    <td>{{friendObj.name}}</td>
    <td>{{friendObj.phone}}</td>
  </tr>
</table>

In this code, use 'ng-model="search.property"' and specify 'strict' in the filter.

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

Sequential Arrangement of JavaScript Functions

Does anyone know how to create an HTML element and then drag it across the screen? I have a function that defines the movement of the element, and I can click on the header to drag the div wherever I want. Additionally, I created a button to add a new div ...

Having issues with sitemap.xml functionality in Next.js post build

I've encountered an issue while working on my Next.js project. Everything runs smoothly in development, but once I build the project for production, the /sitemap.xml URL doesn't return any data. To address this problem, I created a sitemap.ts fi ...

Moving pictures using css3 transitions

Trying to create a straightforward image slider. Below is the provided JavaScript code: $(document).ready(function() { $('#slide1_images').on('click', 'img', function(){ $("#slide1_images").css("transform","translateX ...

Creating a dynamic link in Vue JS is a cinch!

I currently have the following code snippet: <b-dropdown text="Select Factory" block variant="primary" class="m-2" menu-class="w-100"> <b-dropdown-item @click="selectedFactory='China'"> ...

Troubleshooting: jQuery unable to locate element within iframe

I need help finding all elements within an iframe that contain a specific word, for example, 'stack' on this page: http://en.wikipedia.org/wiki/Stack_Overflow Here is the code I am currently using: <body> <iframe src="http://en.wik ...

JSON containing attributes represented by Unicode characters

During the development of my web application, I am interested in utilizing JSON objects with Unicode attributes as shown below: a = { ονομα:"hello" } Subsequently, I would like to access it in this manner: a.ονομα Alternatively, exploring lo ...

Prevent scrolling using mousewheel click (auxclick event)

Currently working with Angular 9 and encountering an issue with the (auxClick) event triggering on a mousewheel click. The problem arises when attempting to use this event while there is a scroll present on the page, as it does not trigger correctly due to ...

The Instant Search feature falls one keystroke short

I’ve implemented a unique "translation" feature on my website which includes an instant search functionality powered by a textarea element. <textarea name="text" onkeydown="searchq();"></textarea> This textarea triggers the execution of the ...

Guide on sending a JSON response from an API endpoint in Next.js

As I work on developing a small REST API for a Next.js application, I encountered an interesting issue. Initially, when I placed my route.ts file in the directory structure rootDir -> app -> api -> hello -> route.ts with the following code snip ...

What is the best way to transmit data to the server using angular.toJson?

I'm struggling to grasp the purpose of angular.toJson. I get that it converts to a JSON object... However, how do I send this object to the server? The server already provides a JSON object with 'GET' requests, but how can I utilize it for ...

Adjust the starting point for div scrolling

Hey there, I've been working on a div element that scrolls along with the user until it reaches the footer of our webpage. I'm facing an issue where I want the scrolling to start only when the user has scrolled 200px down the page. But for some ...

Use AngularJS to extract information from Wikipedia and display it

Just starting out with angularjs and attempting to pull data from Wikipedia to display on the front end. I managed to fetch the data using the php code below: $url = 'http://en.wikipedia.org/w/api.php?action=query&prop=extracts|info&exintro&a ...

Selecting objects within a small three.js view

I am able to showcase an entire page filled with graphical elements using three.js and can even select objects by clicking on them. However, when attempting to display three.js graphics in a small viewport within an HTML page, issues arise. In order to ca ...

Tips for implementing an OR condition within an ng-repeat loop

How can I implement an OR condition within this ng-repeat loop? I am looking to filter the content of this table based on a specific value. MY TABLE <tbody ng-repeat="Fund in ListTask | filter:{CreationDate: manager.start}:t ...

Attempting to trigger an action from a Vuex module proves futile as the error message "[vuex] unknown action type" is generated

I've been struggling to successfully register a Vuex module. Below is the code I've been working with: stores/index.js: import Vuex from 'vuex'; import resourcesModule from './resources'; import axios from '@/helpers/ax ...

What is causing my mobile navbar to not collapse when the page loads?

I'm having trouble collapsing the navbar on mobile devices. Currently, the navbar only collapses when I manually resize the tab. It seems like the issue is related to it not checking the screen size when the site initially loads. I've attempted t ...

Error: posts.populate does not exist as a function

I am currently working on populating the author fields of my post (which are object ids) with their corresponding author objects stored in a separate collection. Here is the code snippet from my controller: exports.readPosts = async (req, res) => { t ...

vue-router: error encountered while attempting to load asynchronous component for rendering

I'm new to vue-router and having trouble getting it to work. When I try to start my app, these errors pop up: [vue-router] Failed to resolve async component render: TypeError: _vm is undefined 49:16:39 [vue-router] uncaught error during route navigat ...

Tips for getting Vue's element-ui validateField() function to function correctly in conjunction with v-if?

Kindly observe the password fields. The fields for 'Password' and 'Confirm Password' are displayed upon clicking on the 'Change Password?' button. The provided code functions properly and effectively validates the form using ...

When I remove the `return false` statement in my code, my AJAX call executes successfully. However, keeping it in prevents the call from

I am using jQuery to send an AJAX POST request without refreshing the page. I have tried using the return false command to prevent the page from refreshing, but then the AJAX POST request doesn't go through. If I remove the return false command, the A ...