Display several modal pop ups using AngularJS

I'm currently using AngularJS and I have a requirement where I need to check if a student ID exists in the database when a user clicks a button. If the student ID is found in the database, I want to display #modal1, otherwise show #modal2. Is it achievable with AngularJS? And if so, how can I implement this?

HTML

<tr ng-repeat="g in students">
  <td>{{g.studentId}}</td>
  <td>{{g.studentName}}</td>
  <td>
    <div class="btn-group" role="group" aria-label="btnActions">
        <button type="button" ng-click="act(g)" title="act" data-toggle="modal" data-target="#deleteModal"></button>    
    </div>
  </td>
</tr>

#Modal that will be displayed 
<!-- modal1 -->
<div class="modal fade" id="modal1" role="dialog">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-body">
                confirm delete?
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-primary" ng-click="delete()">Yes</button>
                <button type="button" class="btn btn-default" > No</button>
            </div>
        </div>
    </div>
</div>

<!-- modal2 -->
<div class="modal fade" id="modal2" role="dialog">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-body">
                Data already existed
            </div>
        </div>
    </div>
</div>

Controller

$scope.act = function (g) {
    g.studentId;
}

Answer №1

Include the following code in your controller:

$scope.act = function(g){
    /*
       Implement logic to verify if student is in database
    */
   if(student_available == true){
       $("#modal1").modal('show');
   }
   else{
       $("#modal2").modal('show');
   }
}

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

Symfony2 and asynchronous JavaScript and XML (AJAX)

Is there a way to perform asynchronous actions in Symfony2 without having to refresh the page? I haven't been able to find any information about this in the official "Book" or "Cookbook". (The only mention I came across was 2 sentences about hinclude. ...

Acquire a set of picture cards for displaying in a grid layout

After creating a cardArray to store card objects, I went through each item in the array to generate images as cards. These card images were then appended to the grid div as children. Additionally, I set up an event listener for the shuffle button. However, ...

Creating an AJAX function to display a popup window for users who are already registered - here's how!

I am currently working on a dropwizard-java project. Whenever users click the subscribe button, it displays a thank you message for subscribing and then checks if the user is already registered. I would like to have a pop-up window immediately show whethe ...

Node.js: Array remains undefined despite being logged on the console

My goal is to download a CSV file, read it line by line, and add the split lines (based on ',') to the tmparray. This code successfully prints all the elements in the array. var request = require('request'); var fs = require('fs&a ...

Determining the cursor location within a character in a div that is content editable using AngularJS

I am facing challenges with obtaining the cursor caret position within a contenteditable div. Currently, I am utilizing the following function : onBlurArea (field, ev) { ev.preventDefault() const editable = ev.target.childNodes[1].childNodes[2] ...

Encountering issues with loading a module in Aurelia

I've encountered a peculiar issue while attempting to load a module using Aurelia. The moment library was successfully loaded for date formatting, but when trying to load the numeral library in the same manner with npm install <module> --save, i ...

What could be causing my PUT and DELETE requests to return a 404 status code?

I have encountered a problem with my MEN back-end app. In the express client router, I declared PUT and DELETE requests but they are returning a status 404 not found error. However, the POST request is functioning correctly. Could this ...

Using jQuery to remove the functionality of a file input button is ineffective

I am having trouble with an input type file element: <input type="file" name="val1" /> And I'm using this jQuery code: $("input[name='val1']").off("click"); However, the above script, which is already included in a $(function() { } ...

Customize the MUI Slider Component with unique colored thumbs

Check out MUI's slider component at this link. I'm using it to let users select a value range with two thumbs. You can find the documentation for MUI's multi-thumb slider here. If you want to customize the style of the slider thumb, visit ...

Enhancing image search functionality through dynamic HTML updates

I need help figuring out how to update the link address for profile pictures on my NHL stats website. Currently, I am using a script to append the image to the body, but I don't know how to properly add the player ID ({{p1_ID}}) to the link and includ ...

Emit Observables within deeply nested callback functions

Hey there! I'm currently working on a web app using Angular2/4 and I've encountered an issue with Observables. My goal is to call a function within a component and then have some code executed once that function completes. Here's the releva ...

Karma testing revealed a TypeError when trying to modify a property that is read-only

While attempting to unit test my controller, I encountered an error. Upon debugging the testcase's expect statement, I found that the expected value is correct but it still fails with the following error message. What could be missing here or am I tes ...

Adjusting Image Size According to Window Resize?

My current issue involves having four images displayed side by side. When the window size is adjusted or viewed on a smaller device, the layout shifts to a line jump (with three images in a row and the fourth one below). What I actually want is for all fou ...

What is the best way to align elements within a row/column layout in Angular Material when working with divs?

To set up two div blocks in a row, I'm utilizing the code below: <div layout="column" layout-gt-xs="row" layout-align="center center" id="row"> <div id="a">a</div> <div id="b">b</div> </div> The CSS for this ...

Making sure that a commitment does not come to fruition

Perhaps this code snippet below functions correctly as it is, but I'm uncertain if it's the best approach to prevent potential runtime issues. Here's the code in question: const ep = `${environment.api.baseUrl}/login`; return this.http.pos ...

Retrieving data from API using Ionic2 to http.post

Here is the code snippet I used to make an HTTP POST call: var creds = encodeURI("name="+name+"&email="+email); var headers = new Headers(); headers.append('Content-Type', 'application/x-www-form-urlencoded'); headers.append(&apos ...

Utilizing Salesforce and DocuSign: A guide to automatically filling in the recipient of my envelope through DocuSign with the contacts from my records

In my Salesforce work, I'm currently customizing the Quote object. The default button labeled "Send with DocuSign" is already included on the Quote layout. My goal is to automatically populate the recipient of the DocuSign envelope with the contact(s) ...

Separate each item in the list and display them across multiple pages within a table

I'm looking to display a list of 37 items across four separate pages within a table. Can anyone suggest a way to split these items and showcase them in four different pages using either javascript or vue.js? ...

I'm having trouble getting my application to output to the console. What could be the issue?

In my cr-route.js file, I have a function that ensures the user is authenticated before displaying their name. module.exports = function (app, passport) { // ===================================== // HOME PAGE (with login links) ======== // == ...

AngularJS custom filter for ng-repeat sorting conditions

I am having difficulty understanding how to create a custom filter. I want the function to filter by ItemID from a dropdown. It is currently working, but I need it to stop filtering if the type is value 8. This is because I am modifying the dataset where i ...