Using Angular's ng-repeat with filtering functionality

Is there a built-in method in Angular for filtering or querying results as you type?

For example:

<input type='text' ng-model='query'>
<table>
    <tr>
        <td>Name</td>
        <td># of Enrollments</td>
    </tr>
    <tr ng-repeat='c in courses | filter:query' onfilter='someStuff()'>
        <td>{{c.name}}</td>
        <td>{{c.enrollmentLength}}</td>
    </tr>
</table>

If I type the letter "a" into the input text, I want it to trigger the someStuff() function.

Answer №1

To achieve this, utilize a timepiece integrated within your controller:

$scope.$watch('input', function(value) {
   // This will trigger when the input is altered
});

Answer №2

Instead of using an expression, the filter in AngularJS can be used to call a function. Take a look at this example:

$scope.processQuery = function(course) {
  // do some processing
};


<input type='text' ng-model='query'>
<table>
    <tr>
        <td>Name</td>
        <td># of Enrollments</td>
    </tr>
    <tr ng-repeat='c in courses | filter:processQuery'>
        <td>{{c.name}}</td>
        <td>{{c.enrollmentLength}}</td>
    </tr>
</table>

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

Trigger an analytics event from a background chrome extension

I've encountered a challenge with sending an event to Google Analytics from background.js, which is the background script of my Chrome extension. This is the code snippet I added to my background.js file: var _gaq = _gaq || []; _gaq.push(['_set ...

Transforming a React Class Component into a React Functional Component

After struggling for a day with multiple failed attempts, I have been unsuccessful in converting a React Class Component. The original class component code is as follows: class NeonCursor extends React.Component { constructor(props) { super(props); ...

jQuery uploadify encountered an error: Uncaught TypeError - It is unable to read the property 'queueData' as it is undefined

Once used seamlessly, but now facing a challenge: https://i.stack.imgur.com/YG7Xq.png All connections are aligned with the provided documentation $("#file_upload").uploadify({ 'method' : 'post', 'but ...

What is the best way to connect an "onClick" event to a JavaScript file?

I have a button that triggers an action when clicked. The javascript code for the button is stored in an external file called example.js, which I linked to the HTML document. How can I ensure that the "onclick" event on the button corresponds to the javas ...

Track the number of function calls using closure and function attribute

Recently, I encountered an issue while trying to track how many times a particular JavaScript function got called. The approach of adding an attribute to the function worked perfectly fine for keeping count, but surprisingly, I faced difficulty when attemp ...

How can an array object be reconstructed by iterating through MongoDB documents in JavaScript?

Currently in the process of reconstructing an arrayObject by iterating through elements obtained from an ajax .get request of MongoDB documents. The arrayObject is close to being correct, but it lacks proper comma separation between the documents within t ...

Invoke index functions within a component

I have a widget/component written in Angular 4 within the index.html file. Before and after this angular app, there are various HTML elements due to the nature of it being an additional component for the website. The head section of the index file include ...

Is there a way to make links in popup.js open in a separate tab?

An innovative chrome extension has been developed to display a dynamic list of links. Check out the code snippet below: function linkPrinter(linkArray) { for (var i = 0; i < linkArray.length; i++) { document.write(linkArray[i].link(linkArray[i]) + "&bs ...

Retrieve an array of object values using Angular and TypeScript

I'm attempting to extract the values of objects in an array using a nested for loop. I am receiving JSON data as shown below and have written the following TypeScript code to achieve this. However, I am unable to successfully bind the values to the te ...

I have incorporated jquery-1.2.6.js into my project but I am encountering difficulties utilizing the live method

C# foreach (DataRow Row in oDs.Tables[0].Rows) { LitPreferances.Text += "<Li ID=LI_" + Row["pk_Preference_Branch_ID"].ToString() +"_"+ Row["pk_Preference_BranchType_ID"].ToString() +">" + Row["Branch_Name"].ToString() + "&nbsp;&nbsp;< ...

React's setState() not reflecting state changes when clicked

I have developed a component that displays data from a Redux store grouped by week. To ensure the week's relevance is maintained within this component, I decided to store its value in local state as shown below: constructor(props) { super(props ...

Testing AngularJS for seamless navigation between pages

I need some guidance with writing e2e tests for my web application. I am new to AngularJS and could use some assistance in getting started with testing. My goal is to create a test that verifies if the user is on the landing page of the app using Jasmine ...

What causes the Route to remain unchanged following an asynchronous function call in React

I am facing an issue with a code pattern that I believe should work, but for some reason, it is not functioning as expected. const MyComponent=()=>{ const history = useHistory(); function sleep(ms) { return new Promise(resolve => setTimeout(r ...

Changing the text of a button using ngClass in Angular's toggle functionality

Is there a way to modify the text of a toggled button class in Angular using Bootstrap? Currently, I have this code to toggle the class: html <!-- toggle button --> <button type="button" class="btn btn-primary mt-3 ml-3" (click)="status=!status ...

File not found - please check the required file paths

How do I resolve the address issue within the "require" function in my PHP code? I am receiving an error message that reads: Warning: require (..) failed to open stream: no such file or directory. https://i.sstatic.net/OQvQ6.jpg https://i.sstatic.net/pIR ...

Removing curly braces and double quotes from an array object can be achieved by iterating through each element

Within this particular project, I have utilized Angular 8 and TypeScript. In the implementation, there exists an array that showcases emails either through user input or via CSV upload. Once the user inputs several emails, a button is available to send in ...

Utilizing API data to set the state in a React component

In my quest to modify the state of this React component, I have a variable called rankAndTeam that holds the "prints=>" data listed below. My goal is to assign "Washington Capitals" to this.state.teamRank["0"], "New York Islanders" to this.state.teamRan ...

Adjust the height of an element when an animation is initiated (Angular)

Check out the transition I've set up to smoothly slide between my views: https://plnkr.co/edit/yhhdYuAl9Kpcqw5tDx55?p=preview To ensure that both 'panels' slide together, I need to position the view absolutely. However, this causes the view ...

Is it possible to obtain a single symbol from the string upon clicking?

I am working with a DOM document that contains text content like this: <p>Content scripts aren't completely cut off from their parent extensions. A content script can exchange messages with its parent extension</p> When I click on this H ...

Discovering the method to retrieve custom headers from an Angular $http response

Check out the code snippet below: $http({ method: 'POST', url: myURL, headers: { //BLAH }, data: { // BLAH BLAH } }).success(function(data, status, headers) { ...