How are parameters included in the ng-model of AngularJS?

Currently, I am delving into the realm of Angular.js and grappling with the concept of ng-model. It appears that ng-model allows us to bind input values to the $scope object in a controller. However, as I ventured into Angular.js filters, I stumbled upon an example on the official website regarding filters in angular js. The example provided left me puzzled about:

<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>

In analyzing the above snippet of code, my inquiry pertains to how we append parameters to the ng-model and subsequently access them. Especially since ng-init includes "friends," I am curious about the correlation between this initialization and utilizing search for filtering or searching. How does specifying search.name or search.phone facilitate accessing friends.name and friends.phone correspondingly?

Answer №1

Acquaintances is an array of objects. Each object in the Acquaintances array contains properties for both name and phone. This array is initialized using ng-init as mentioned.

You also have a query object (model) within your scope. It also includes name and phone properties.

The syntax

contactObj in acquaintances | filter:query:strict
represents the standard way to use the filter directive. This expression filters the "acquaintances" based on the values in the "query".

When you apply a filter to the acquaintances (object array) using the query object, AngularJS essentially goes through each item in the acquaintances array and retrieves records that satisfy both contactObj.name == query.name and contactObj.phone == query.phone (in strict mode). Setting the last parameter to false allows for substring matching instead.

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 clearing a div with Jquery

I'm having trouble emptying the am-container with my jQuery code. Here is what I currently have: jQuery(document).find("div[id='am-container']").html(''); Below is the HTML structure: <div class="mid-part-right"> <div ...

Retrieving the file name from the line number within the trace stack or Error object

I'm working on enhancing my error handling in Node.js/express. Does anyone know a method to retrieve the filename and line number where an error occurs in my code? error-handler.js, utilizing console.trace, only handles errors at the route level...n ...

The requested resource does not have an 'Access-Control-Allow-Origin' header. This means that access from 'http://localhost:4200' is not permitted

I am trying to make a call to a Spring REST web service from an Angular HTTP service using the get method. However, I am encountering the following exception: Failed to load : Response to preflight request doesn't pass access control check: No ' ...

Error message: Unable to split path as a function when utilizing React hook forms in conjunction with Material UI

Check out this code snippet: <TextField name="name" required className='my-2 mx-auto' label="Full Name" variant="standard" style={{ "width": "60%" }} value={name} onChange={(event) => { set ...

Is it possible in Angular to generate a module and component without including a CSS file in a single command?

Is it possible to generate a Module linked to a component without automatically creating a css file? For example, the default method I've been using involves: ng generate module name / ng generate component name This results in the typical componen ...

Deleting tasks from the to-do list using Node.js and Express with EJS

Looking to implement functionality where each list item can be removed from a Node.js array by clicking on an HTML button using EJS and Express: I am considering placing an HTML button next to each list element so that the selected element can be removed ...

Having difficulty modifying elements within an array using AngularJS techniques

Hey there, I'm just starting to dip my toes into AngularJS. I'm attempting to add and remove elements in an array, but I'm struggling to achieve the desired outcome. Here's the JSON structure I'm working with: $scope.masters = [ ...

Eliminate duplicate items using the reduce method in JavaScript

Working with a set of Json Objects, I use a javascript map function to list each field along with an array of its possible types. For example: birthDate, [Date, String, String, String, String] isMarried, [Boolean, Boolean, Boolean, Boolean, String] name, ...

How can you ensure a code snippet in JavaScript runs only a single time?

I have a scenario where I need to dynamically save my .env content from the AWS secrets manager, but I only want to do this once when the server starts. What would be the best approach for this situation? My project is utilizing TypeScript: getSecrets(&qu ...

Create a stylish rotating div using CSS3 animations combined with AngularJS to give it a modern

Here is the link to my fiddle: http://jsfiddle.net/7kLde/48/ I have noticed that the rotation of the div appears more like a flip rather than a smooth rotation. Currently, I am using the latest version of angularjs 1.2 rc3. With the new animation cap ...

Error encountered in Browserify bundle.js: exec function is not executable

After setting up Node.js, npm, samba-client, and browserify on my system, I encountered a frustrating issue in my bundle.js file. An Uncaught TypeError related to the 'exec' function has been causing trouble, and despite my efforts, I have been u ...

Tips for incorporating broadcasting into my Angular application?

console.log('js'); var myApp = angular.module('myApp', ["ngRoute"]); myApp.config(function($routeProvider) { $routeProvider.when('/', { templateUrlnp: 'views/partials/logIn.html', controller: 'LoginC ...

Collaborative use of AngularJS data models

In my Angular app, I have a controller called CanvasController that controls a canvas where users can add "widgets". The controller has an array named _currentWidgets, which holds object literals representing the widgets currently on the canvas. For examp ...

Using Node.js to read from a file and write the character 'Ł' to another file

I am facing an issue with an ANSI file that contains the character 'Ł'. My goal is to extract this character and save it to another file while preserving the same encoding to retain the 'Ł' character. const fs = require('fs&apos ...

Trigger a click event on every link with a specified delay

In my jQuery project, I am working with a set of links, each of which has the class .refresh I am trying to create a function that will trigger a click event on each link with a 10-second delay between each click. However, the current code I have fires t ...

When utilizing the map function with an array containing 168 objects in the state of a React application, a freeze of around 1

I encountered an issue when trying to update a property in a state array of objects after executing an axios.put request. Here is my code: States - useEffect //... const [volunteers, setVolunteers] = useState([]); //... useEffect(() => { async fu ...

Displaying JSON data in a browser using Node.js without the need for refreshing the page

I am currently working on a node.js server that fetches JSON data from an external source and displays it in a browser window. I need assistance in setting up an automatic update every minute to reflect any changes in the JSON without requiring a manual re ...

Issue with AngularJS ng-view not displaying information

I am currently studying Angularjs through the Tuts+ Easier JavaScript Apps with AngularJS tutorial. I have reached the section on Routing Primer using ng-view and I am attempting to display the list page contents in the ng-view of the index page. However, ...

Integrating Illumination into a ShaderMaterial in three.js

I'm exploring the idea of creating a ShaderMaterial with lighting similar to that of a MeshLambertMaterial. To achieve this, I have developed a vertex and fragment shader (available here) and included the uniforms from THREE.ShaderLib[ 'lambert&a ...

Construct a string by combining the elements of a multi-dimensional array of children, organized into grouped

My task involves manipulating a complex, deeply nested array of nodes to create a specific query string structure. The desired format for the query string is as follows: (FULL_NAME="x" AND NOT(AGE="30" OR AGE="40" AND (ADDRESS ...