Displaying concealed information from the chosen row in a listBox using AngularJS

Here's what I have:

I have a table with student data such as ID, Name, LastName, and From. I recently added a new class to the project called BankAccount.

Each student can have zero or more accounts which I have added through a data-binding process.

My current goal is to select a student and display their accounts (if any) in a listBox on the same page. This is the code I have so far:

The table containing student information:

    <table border="1" name="tableStud" arrow-selector>
        <tbody>
            <tr>
                <td>ID</td>
                <td>First Name</td>
                <td>Last Name</td>
                <td>From</td>
            </tr>

            <tr ng-repeat="student in result"
                ng-class="{'selected':$index == selectedRow}"
                ng-click="setSelected(student,$index)">
                <td>{{ student.id }}</td>
                <td>{{ student.firstname }}</td>
                <td>{{ student.lastname }}</td>
                <td>{{ student.mestorodjenja.ime }}</td>

            </tr>

        </tbody>
    </table>


 <select ng-model="student.accounts" multiple="multiple"
                ng-options="account.name for account in student.accounts track by account.id"

        >
        </select>

In the controller, I have this function:

$scope.setSelected = function(student, index) {
    $scope.student = student;   
    $scope.selectedRow = index;
};

Currently, my issue is that all the accounts in the listBox are selected and when I click on one, the others disappear but remain selected. Furthermore, if I switch to another student and then come back, the disappeared accounts are still missing and the old one remains selected.

My question is:

Is it possible to show the student and their accounts in the listBox without them being automatically selected, and also prevent them from disappearing after being clicked?

Thank you in advance!

Answer №1

Simply substitute the variable for the chosen student. For example:

$scope.setChosen = function(student, index) {
   $scope.chosenStudent = student;   
   $scope.chosenRow = index;
};

HTML :

 <select ng-model="student.accounts" multiple="multiple"
            ng-options="account.name for account in chosenStudent.accounts track by account.id">
 </select>

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

How to retrieve an array as a List using Java

Here is the relevant code snippet that I am posting: Within the table class, I have defined: class Table extends AbstractTableModel { private List<String> columnHeaders; private List<Object> tableData; public Table(SortedSet<String ...

Gather information from various Mongoose requests and forward it to the specified route

Recently embarked on my journey of learning Express with the help of online resources. While I have been able to handle pages dependent on a single query, I have hit a roadblock when it comes to creating a pagination table. In this scenario, I need to exec ...

Angular 2 Guide on macOS Sierra Shows "Page Not Found" Error in Web Browser

I've been delving into Angular 2 with TypeScript on my OS X machine. Following the tutorial to the T, I didn't encounter any errors during compilation. Upon executing the npm start command, everything seemed to be smooth sailing as a new tab open ...

Sign in and create an account seamlessly on a single page with React

Looking for a way to integrate login and register functionalities on one page using React with TypeScript. However, facing an issue where the login component briefly displays before switching back to the signup component. Unable to determine why the stat ...

Create a new JavaScript object called "tree" with nested objects at any depth

My goal is to initialize a JavaScript object with empty objects containing a single key. For instance: getObject('one.two.three') Should create the object: {one:{two:{three:''}}} It seems that initializing with dynamic key names is ...

The RangeError occurs when attempting to deploy to Heroku due to exceeding the maximum call stack size at Array.map in an anonymous function

While attempting to deploy a MERN stack application to Heroku, I encountered an error in the Heroku CLI. RangeError: /tmp/build_c861a30c/frontend/node_modules/@reduxjs/toolkit/dist/redux-toolkit.esm.js: Maximum call stack size exceeded at Array. ...

Choose a cell from a separate column within a React application

Currently, I've been developing a puzzle game using React JS. My goal is to be able to choose one cell in each column, but I haven't been successful in achieving that yet. You can find the code sample here. Any assistance you can provide would be ...

Steps for Adding npm Dependencies to Your Chrome ExtensionWould you like to learn

I am currently developing a Chrome Extension that relies on a GraphModel from tensorflowjs. To import my model, I need to utilize the tf.loadGraphModel function provided by the tensorflowjs package. Is there a method to properly import these packages int ...

Creating an external link in Angular with query parameters

I have created an app where users have their addresses listed, and I want to implement a feature that allows me to open Google Maps when clicking on the address. However, I am currently facing an issue where instead of getting the actual value of {{ this. ...

What are the steps to switch to a root page after a successful sign-in with Ember-Auth?

After successfully implementing Ember-Auth using a pure token based approach, I am facing a challenge in redirecting users to the root of my app once they sign in. Although I know about actionRedirectable (refer to for details), since I am using a pure t ...

Currently, I am working on developing a to-do task manager using Angular 2. One of the tasks I am tackling involves updating the value

I'm facing an issue with managing to-do tasks. I would like to update the value of an option in a select dropdown when the (change) event is triggered. There are 2 components: //app.component.ts //array object this.dataArr[this.counter] = {id: this ...

Different ways to incorporate Grouping and Dependency in @BeforeMethod in TestNG

How can I make sure that the @BeforeMethod depends on the @Test in my scenario where different TestMethods have different setups? Here is a code snippet for better understanding: @BeforeMethod(groups = {"gp2"}) public void setUp1() { System.out.printl ...

Implementing validation in ASP.Net along with JavaScript for both the update and cancel buttons

My main objective is to show a message during the server roundtrip of an ASP.Net WebForm. Within my WebForm, there are two buttons: an update button and a cancel button. The message should always appear if either the update button or the cancel button is c ...

"Looping too much in the for loop leads to a crashing browser

How to Retrieve Variables Outside the HTTP Scope in AngularJS I am trying to create a multi-select dropdown that initially fetches the first 5 data entries from a JSON file and then loads more data when the "show more" button is clicked. I have declared a ...

Exploring Java's Generics and Wildcards within Collections

While working on a test class with AssertJ, my code looks like this: public void someTest() { assertThat(getNames()).has(sameNamesAs(getExpectedNames())); assertThat(getNames()).doesNotHave(sameNamesAs(getOtherNames())); } private List<String& ...

Unable to choose anything within a draggable modal window

Can someone please assist me? I am struggling to figure this out. I can't select text inside the modal or click on the input to type text into it. I suspect it may be due to z-index issues, but I'm having trouble locating them. var currentZ = n ...

Error encountered while trying to upload a file using PHP on a hosting platform

Hey everyone, I'm feeling really frustrated right now because I'm facing a file upload error in my PHP code. The issue is that the file is not getting uploaded to my folder and no error messages are being displayed. I've been working on cr ...

Transform the snake code by incorporating a visual image as the face of the serpent

Can someone help me change the snake's face to an image instead of a color fill in this code? And how can I add arrows for mobile compatibility? (function() { // Insert JS code here })(); // Insert CSS code here This code snippet includes functi ...

Implementing Vue.js Popover for Individual Dropdown Items: A How-To Guide

I need unique information text to display for each dropdown item when hovered. I am using bootstrap-vue and have a loop set up for the dropdown items. <b-dropdown :text="currentColorType"> <b-dropdown-item v-for="colorType in co ...

Filter a list generated in real-time according to both the unique identifier and the text entered in a search box

WORKING $(document).ready(function() { $("#submit").click(function() { $.ajax({ url : "/vmstatus/", type : "POST", dataType: "json", ...