Refinement of chosen selection

Is there a way to dynamically filter the content of a table based on the selected option?
I want the table to refresh every time I change the option in the select dropdown.

HTML

<select ng-model="selectedGrade" ng-options="grade.Id as grade.Title for grade in grades"></select>

<table>
<tr>
    <th>ID</th>
    <th>Description</th> 
</tr>
<tr ng-repeat="attr in attributes|filter:{grade:selectedGrade.Title}">
    <td>{{attr.id}}</td>
    <td>{{attr.name}}</td> 
</tr>
</table>

Module

angular.module('Employee',[])
.controller('EmployeeCtl',function($scope){
    $scope.grades=[
       {"id":1,"Title":"MTS"},
       {"id":2,"Title":"SMTS"},
       {"id":3,"Title":"PMTS"},
       {"id":4,"Title":"CMTS"}
    ];
    $scope.attributes=[
       {"id":1,"name":"Greg","grade":"MTS"},
       {"id":2,"name":"Marlon","grade":"SMTS"},
       .........
    ];
});

Answer №1

To include {{ selectedGrade }} in your template, simply add it. The value stored in selectedGrade will be the ID of the grade that is currently selected because you used:

grade.Id as grade.Title for grade in grades

If you prefer selectedGrade to contain a complete grade object instead, then use:

grade.Title for grade in grades

For more information, refer to the documentation.

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

Is there a way to alter the variant or background of a clicked button exclusively through reactjs? If so, how can I make it happen?

My goal is to change the variant of a Material UI button from outlined to contained or simply change its background color when it is clicked. I am unable to use the onFocus property due to conflicts with another component. Here is my current method, but ...

Using AngularJS: Passing input parameters through the URL using ui-router

While browsing through this particular question, I became interested in making a modification. My goal is to have the input entered into the 'home' field display in the 'other' field. I attempted to link the input using {{name}}, but I ...

Transmit a file using multipart with XMLHttpRequest

Is it possible to use XMLHttpRequest to send a multipart file to a servlet? I am currently working on a form that needs to be submitted as multipart, but I am not receiving a response after successfully uploading it. It is important that the process happe ...

Using custom icons with AngularJS and Bootstrap input fields

Having a bit of trouble here - whenever I try to externalize my input, the position of my glyphicon seems to be off. Can't quite figure out why. <div class="form-group" ng-class="{ 'has-error has-feedback& ...

Is it necessary for vertex labels to be distinct within a graph?

I am currently developing a browser-based application that allows users to create graphs, manipulate them, and run algorithms on them. At the moment, each vertex is represented by a unique positive integer. However, I am considering implementing labeled ve ...

Unlock the secrets of recovering deleted data from a text area in Kendo UI Angular

Currently working with Kendo UI for Angular, I need to capture deleted content and remove it from another text area within the same component. My project is using Angular-13. I'm stuck on how to accomplish this task. Any suggestions would be greatly ...

Checking the correctness of an entered regex pattern and example

My form contains two textboxes - one for entering a regex pattern, and the other for inputting text. I am attempting to validate if the entered regex pattern matches with the input text. Check out my simple code snippet. Here's a demo of it in acti ...

Template for Vue.js Component Registration

Below is a simple Vue component example: const MyComponent = Vue.component('my-component', { data () { // data here... }, methods: { // methods here... }, template: '<p>Hello, world !!!</p>' }); I ...

Is it feasible to use HTML to improve IE's tolerance for errors in markup, such as unnecessary tags?

I created a jQuery tabs element in the following way: <div id="tabs"> <ul> <li><a href="#tabs-1">Nunc tincidunt</a></li> <li><a href="#tabs-2">Proin dolor</a></li> < ...

Displaying an IP camera feed on a three.js canvas

I've been presented with a seemingly straightforward task in JavaScript that I'm not very familiar with. The challenge is to take an IP camera stream and display it on a three.js canvas. To start, I came across an example that uses a webcam inst ...

What is the extent of statement coverage in Karma?

Currently, I am conducting tests using the karma tool. However, I am facing difficulties in covering the code within a foreach statement. Can you please advise me on how to achieve coverage for this code using jasmine test cases? https://i.sstatic.net/ErG ...

Using arrays as props in React with Typescript

In my code, I have a Navbar component that contains a NavDropdown component. I want to pass an array as a prop to the NavDropdown component in order to display its dropdown items. The array will be structured like this: DropDownItems: [ { ...

What is the best way to include an API key in the response to an Angular client application?

I'm working on transferring my API key from NodeJS to an Angular client application using $http, but I am unclear on the approach. Below is a snippet from my NodeJS file: // http://api.openweathermap.org/data/2.5/weather var express = require(' ...

Automatically resize ui-select dropdown box to the left side

I've been tasked with incorporating AngularJS ui-select into my project, specifically creating a multiselect dropdown. Currently, the dropdown box automatically adjusts its width based on the length of the longest selectable text, causing it to extend ...

What is the best way to use CSS in ReactJS to insert an image into a specific area or shape?

Currently, I'm working on developing a team picker tool specifically for Overwatch. The layout consists of cards arranged horizontally on a website, all appearing as blank gray placeholders. These cards are positioned using the JSX code snippet shown ...

What steps can I take to display lines in a textarea so that it closely resembles the appearance of a notepad document

Is there a way to display lines in a text-area to give it the appearance of a notepad? I only have one text-area available. See the example notepad below for reference. ...

Mastering the art of seamless navigation within a single page through the magic of

I have two HTML pages: "Login.html" and "index.html". Instead of a normal href linking, I want the user to navigate to "index.html" when they click on the login button. Furthermore, I want the index page to be displayed within the codes of login.html, cre ...

Mastering the Art of Defining JavaScript Classes in React-Native

In my React Native project, I am faced with a situation where I need to create a new class: class customClass { email: string; name: string; constructor() { setUser(fbid: string, token: string): boolean { To keep things organized, I decide ...

Mapping over an array and ignoring any undefined properties in a dynamic object

Looking for a way to dynamically create objects in the 'map' function to reduce the final array size. The goal is to avoid adding properties with undefined values. For example, if 'offst: undefined', skip this property but add others wi ...

Dealing with issues of toggling visibility with jQuery when using a dropdown menu

Inside a hidden drop down div, the focus is on "DC" right now. In the image below, we are looking at sales: HTML: <td class="edit"> <select class="touch" style="display: none;"> <option value="11">Rebuying</option><option value ...