Begin filtering data in AngularJS using the `startWith` filter and an

I've been trying to utilize the startWith filter, but it seems to be operating incorrectly, especially when dealing with the letter P. Please help me identify my mistake in this scenario.

Controller code -

var app = angular.module('filterSample', []); app.controller('filterCtrl', function ($scope) {

$scope.data = {
    messages: [
        {       
        "id":"111619EEVz",
        "name":"Tom 67",
        "status":"Pending"
        },
        {
            "id":"115419EEAA",
            "name":"Business 34",
            "status":"Pending"
        },
        {   
            "id":"1B167000WW",
            "name":"Jack 78",
            "status":"Active",
        }
    ]
  }

  $scope.startsWith = function (actual, expected) {
    var lowerStr = (actual + "").toLowerCase();
    return lowerStr.indexOf(expected.toLowerCase()) === 0;
  }
});

HTML -

<div ng-controller="filterCtrl">
      <input type="text" ng-model="search" />
        <ul border="1px" ng-repeat="msg in data.messages | filter:search:startsWith">
          <li>{{msg.name}}</li>
        </ul>
    </div>

Working Plnkr - http://plnkr.co/edit/tByYZ3jpEk7YPpJnMY11?p=preview

Edit 1 -

Filtering should be like it should only search in name property rather than searching in whole object.

Answer №1

Update the ng-model to search.name

<div ng-controller="filterCtrl">
  <input type="text" ng-model="search.name" />
    <ul border="1px" ng-repeat="msg in data.messages | filter:search:startsWith">
      <li>{{msg.name}}</li>
    </ul>
</div>

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

Issues with Dependency Injection in Angular.js

I've been working on Dependency Injection and trying to make my code more modular in Angular.js. After researching some tutorials, I decided to try and rewrite it. Here's what I initially planned (although I may have misunderstood some concepts, ...

Tips for accessing store data within the mounted lifecycle hook in a Vuex component

In my project, I have the main root component called App.vue and another component named FileUploaderParent.vue. I am using a dispatch promise to store data in the Vuex store. The dispatch call is made under the mounted lifecycle hook. However, when I try ...

Utilizing vue-router to create two separate navigation bars where only one link is highlighted as active

In my setup, I have implemented two sections with navigation structured as follows: <ul class="navigation-list"> <li v-for="(route, index) in navRoutes"> <router-link :to="route.path"> <span>{{ route.name }}</span> ...

Is there a way to convert a json array to a javascript array in AngularJs?

I am new to Angular and front-end development and facing a challenge that I can't seem to overcome. After reassigning one variable to another: $scope.testarray = $scope.todos; only the 'todos' data is being displayed when using Angular bind ...

Instructions on how to send input from a React JS user interface to a Node.js service

I am a beginner in using React JS and have a general inquiry. Typically in React, the recommended approach is to create a state object for input controls and assign its value to that input before submission. This method works well when dealing with 2-5 con ...

disregarding specific characters in a JavaScript string

Currently, I'm utilizing the themoviedb API to incorporate movie posters onto a webpage using the JSON data they provide. The snippet of code I have is as follows: <div id="poster"></div> Here is the JS/jQuery code snippet: $(document) ...

Tips on coding javascript within an MVC4 C# environment

I am currently working with MVC 4 and facing an issue where I have the same action name for multiple views. This makes it difficult to write JavaScript code in all pages individually. Can I simply write the JavaScript in the C# action result instead? I at ...

Navigating after submitting a form using the Location header in jQuery

Seeking a way to utilize the Location header in jQuery 1.7 for redirection to a target. The current code is structured as follows: $('#creationLink').click(function(){ $.ajax({ type: 'POST', url: '/', success: ...

How come I am unable to expand a collection of objects using Zustand?

I am currently utilizing Zustand in a TypeScript Next.js application. Strangely, whenever I attempt to loop through my state object, I encounter a runtime error message. The structure of the damaged zone object for my car is as follows: const damagedZones ...

Passing in additional custom post data alongside serializing with jQuery

function MakeHttpRequest( args ) { var dataToSend = "?" + $("form[name=" + args.formName + "]").serialize(); $.ajax({ type: "POST", url: args.url + dataToSend, data: { request: args.request }, su ...

Develop a dynamic modal feature that allows users to input SQL queries and execute them seamlessly without having to

I need to implement a feature in my web application where users can set the price of an item displayed in an HTML table that is populated from a MySQL database. When a user clicks on a button next to a row, a modal should open with a text input field and a ...

Assign a class to each element that the mouse hovers over while simultaneously clicking the mouse

I am faced with a scenario where I have three boxes: div { display: inline-block; width: 100px; height: 100px; border: 1px solid black; cursor: pointer; } div.selected, div:hover { background-color: red; color: white; } <div>A</d ...

The dropdown feature of the Angular-UI typeahead directive is not functioning

Recently, while using the AngularUI typeahead directive, I encountered an issue where the dropdown appeared cut vertically with a scrollbar on the right. Despite this visual glitch, all the data was displaying correctly within the typeahead box. The image ...

Hover over with your mouse to open and close the dropdown menu in React JS

Just starting out with React JS and encountering a small issue. I'm trying to make the menu disappear when the mouse leaves that area, so I used onMouseOut and onMouseLeave to close it. However, I noticed that having these options in place prevents th ...

Selecting either "THREE.NearestFilter" or "THREE.LinearFilter" will result in the black plane

During my experimentation with the THREE.js library, I encountered a notification stating: THREE.WebGLRenderer: Texture is not power of two. Texture.minFilter should be set to THREE.NearestFilter or THREE.LinearFilter. To address this issue, I made the ...

Exploring the development of a customized Google Map using JavaScript within the Angular framework

I'm facing an issue with creating a Google map using PubNub and Angular. The map doesn't display when using the Angular framework, but it works fine with just JavaScript and HTML. Can someone point out what I might be doing wrong? HTML: app.com ...

Retrieving the object ID of an Open Graph from a page's URL

Is there a way to obtain the Facebook Object ID associated with a page directly from the page itself? For instance, if I requested the Object ID 325186347604922, this is what I received: <pre> { "url": ".../ricetta-bigne_salati.htm", "type": " ...

The Google Maps Geo service is experiencing a JSONP error with an unexpected token or an invalid label

We have been retrieving user information based on latitude and longitude successfully for some time. However, recently we encountered an error in our code. Here is the snippet of our code: var reverse_geo_url = "http://maps.google.com/maps/geo?q=" + lat ...

Updating Text in Textarea upon Selection Change

Need assistance with updating the content of a textarea based on a select option change. Below is an example of my code: <tr><td>Template:</td><td> <select t name="template" onChange = "setTemplate();"> <option ...

Terminal throws an error stating that no default engine was specified and no extension was provided

I have been working on executing a backend program in Node.js using MongoDB. I have created a form with two input fields for password and name. I am not utilizing any HBS or EJS and my VS Code terminal is displaying the following error: No default engine ...