Utilize AngularJS to effortlessly filter and search data

I am facing an issue with my AngularJS code for searching text. The rows in the table are not being displayed properly and the search functionality is not working effectively.

<html ng-app="myModule">
    <head>
        <title>TODO supply a title</title>
        <meta charset="UTF-8">
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
        <script src="Scripts/angular.js" type="text/javascript"></script>
        <script src="Scripts/Script.js" type="text/javascript"></script>
        <link href="Styles.css" rel="stylesheet" type="text/css"/> 
    </head>
    <body>
        <div ng-controller="myController">
            <input type="text" placeholder="Search name" ng-modle="searchText.name" />
            <input type="text" placeholder="Search city" ng-modle="searchText.city" />
            <input type="checkbox" ng-model="exactMatch" /> Exact match
            <br /> <br />
            <table>
                <thead>
                    <tr>
                        <th>Name</th>
                        <th>Gender</th>
                        <th>Salary</th>
                        <th>City</th>
                    </tr>
                </thead>
                <tbody>
                    <tr ng-repeat="employee in employees | filter:searchText:exactMatch">
                        <td>{{employee.name}}</td>
                        <td>{{employee.gender}}</td>
                        <td>{{employee.salary}}</td>
                        <td>{{employee.city}}</td>                      
                    </tr>                    
                </tbody>
            </table>       
        </div>
    </body>
</html>

Javascript

var myApp = angular.module("myModule",[])
                   .controller("myController", function ($scope){
    var employees = [
       {name:"Ben", gender:"Male", salary:55500.00, city:"London"},
       {name:"Thomas", gender:"Male", salary:56000.00, city:"Melbourne"},
       {name:"Lin", gender:"Male", salary:78000.00, city:"Texas"}, 
       {name:"Ben", gender:"Male", salary:85000.00, city:"Sydney"},
       {name:"Ben", gender:"Male", salary:44000.00, city:"Singapore"}
    ];
    $scope.employees = employees;
});

Check out this jsfiddle link Can anyone please point out what I might be doing wrong?

Thank you

Answer №1

You are facing a couple of challenges: 1) The absence of ng-app in the jsfiddle is causing issues. 2) There are a few instances where ng-model has been misspelled.

To see your code functioning correctly, check out this link on jsbin: http://jsbin.com/tahiwocuvu/edit?html,css,js,output

Answer №2

If you want to correctly spell the word "model", simply check out this example: http://jsfiddle.net/Lvc0u55v/10785/

<input type="text" placeholder="Search name" ng-model="searchText.name" />
<input type="text" placeholder="Search city" ng-model="searchText.city" />

Answer №3

Ensure that you correctly add the ng-app tag (which is missing from your fiddle) either through the jsfiddle options or in your code. To get your search function to work properly, make sure you spell ng-model correctly. Don't forget to include AngularJS in your fiddle from the JavaScript options. Check out this link for a functional version of your code: Here.

Answer №4

There appears to be a typo in the ng-model directive (ng-modle)

<input type="text" placeholder="Search name" ng-model="searchText.name" />
<input type="text" placeholder="Search city" ng-model="searchText.city" />

Answer №5

You have a spelling error

<input type="text" placeholder="Enter name to search" ng-model="searchText.name" />
<input type="text" placeholder="Enter city to search" ng-model="searchText.city" />

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

Challenges Encountered with Random Image Generator in JavaScript

I am encountering an issue with a script that is supposed to change the default images to a random image each time the page is refreshed. However, I keep receiving an error stating that boxID is null. Why is boxID null? <script type="text/javascript" ...

Instead of pushing multiple items, focus on pushing only one item at a time

I've encountered an issue while attempting to add a new item to my favlist. Using a for loop, I check if the item already exists in the favlist. However, instead of adding the new item only once, it ends up being added multiple times. What would be ...

Utilizing JSON information acquired through AJAX within a distinct function

Sorry if this question has been asked before, I tried following suggestions from another post but they didn't work for me. What I'm trying to do is fetch some JSON data, save a part of it in a variable, and then use that variable in a different f ...

Utilize JavaScript to extract data from an XML file through a specified

Hello, I am new to JavaScript, Currently, I am working on a project where I need to parse an XML File using JS and jQuery. Could you please advise on how to open an XML file based on its URL? var xml = "File.xml", xmlDoc = $.parseXML( xml ), $xml = $( x ...

Utilizing Express Session with Vue CLI in a Node.js Environment

Developing a nodejs backend for my Vue application has brought up a challenge regarding user sessions and database operations. I initially tried using express-session, but the sessions appeared as undefined in subsequent requests. How can I address this is ...

"Encountering an issue with toUpperCase function in Next.js when incorporating slug - any

Clicking on the following link will take you to the Next.js API reference for configuring headers: https://nextjs.org/docs/api-reference/next.config.js/headers When adding the x-slug key, the code snippet looks like this: module.exports = { async heade ...

The Document.querySelector() method is not displaying every element

As a beginner, I am currently exploring the world of relative CSS selectors and JSPath for my automation scripts. During my journey, I noticed that there are differences in the return statements between these two methods. Below is an example demonstrating ...

Pressing the shortcut key will activate the function specified in ng-click,

I have been searching for a solution to my problem, but I haven't found anything that really helps. What I am looking for is a shortcut within an ng-click directive where there is only an if condition without an else expression. Essentially, I just wa ...

Mobile website menu selection

I want to create a select menu for my mobile website. I have added the select HTML code to my page. <select id="menu_mobile"> <option value="" selected="selected">Navigation</option> <option value="http://example.com/about"> Ab ...

Toggle visibility of DIV based on Selection Drop Down

In an attempt to toggle a variable DIV using the code below: $('#'+content_id).toggle(option.hasClass(show_class)); I have encountered difficulty getting the variable ID. It seems that I am either naming the variable incorrectly or placing it i ...

Chrome successfully processes Ajax request, but Firefox encounters failure

I've encountered a peculiar issue with a JavaScript function that is responsible for making an Ajax call to a PHP page for database transactions and data processing. Take a look at the function below: function processQuizResults() { console.log(" ...

I am utilizing Vue.js to create a duplicate input field and dynamically increasing the index

When a user clicks on the "add another" button, I want to create a duplicate text input field and increase the index of the new field. I found this question that is similar, but the solution provided did not successfully increment the index. The current i ...

Tips for choosing an image using jQuery from an external HTML page

I'm attempting to embed an HTML page within a div and then individually select all the img tags within that page to display an overlay div on top of the images. Currently, I can insert the HTML into a div named "asd" and it seems like the jQuery is f ...

Is it possible that the rows variable is not updating correctly due to an issue with the setState function, resulting in the changes not being displayed in

This code serves a similar purpose to a ToDo List feature. The add button is intended to add an array object to the list of rows, which are displayed in the UI as TextFields through iteration with rows.map. The subtract button should remove the selected ro ...

Can an infowindow be automatically closed based on specific criteria?

Show the infowindow only when hovering over the marker. It should disappear when moving the mouse away from the marker. The infowindow should stay open only if you click on the marker, and can be closed by clicking the close button on the infowindow. ...

Having trouble with sending an AJAX request to a different domain?

I've been attempting to utilize the following API: However, upon making an AJAX call, I encounter this specific error: XMLHttpRequest cannot load /radius.json/30341/10/mile. No 'Access-Control-Allow-Origin' header is present on ...

Using NodeJS to assign key-value pairs to a JSON object

I am currently working with a NodeJS script that receives data in the form of "key, value" pairs and I need to transform this data into a JSON object. The data is obtained using SNMP where the key corresponds to the OID. My goal is to efficiently map thes ...

Validation of PO Box Addresses Using Regular Expressions

I'm having trouble getting the alert to work with my code. $(document).ready( function (){ $("[id*='txtAddress1S']").blur(function() { var pattern = new RegExp('\b[P|p]*(OST|ost)*\.*\s*[O|o|0]*(ffice|FFICE)*& ...

Angular 7 - Issue with rendering only the "dist" folder on the browser, not the "src" folder when using nodejs

Greetings! I'm embarking on a new project involving a nodejs app with angular7. Below is the content of my mail server.js file in nodejs: var express = require('express'); var mysql = require('mysql'); var bodyParser = require(&a ...

Incorporating role-specific paths in Vue Router using Pinia

Is it possible to load one of three potential routes based on a user's role in my pinia store? The issue I'm currently facing is that the pinia store doesn't appear to be initialized before the router is set, resulting in the error Uncaught ...