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

Loading jQuery on document ready with an Ajax request can lead to slow loading times

My current project involves a significant number of ajax requests being made on document.ready. Additionally, I have ajax requests for every database transaction. These requests are all managed in a JS file, with each ajax request corresponding to a PHP pa ...

Syntax of the Vue.js application object model

Just delving into the world of vue.js and stumbled upon this code snippet. Curious to know more about its structure. const CounterApp = { data() { return { counter: 0 } }, mounted() { setInterval(() => { this.counter++ ...

Having trouble accessing data from the local storage?

const headers = new Headers({ 'access_token' : accToken, 'Content-Type': 'application/json', }); axios.post(baseURI, data, { headers: headers }) ...

Remove the active class after it has been clicked for the second time

Currently, I am working on a menu/submenu system where I want to toggle active classes when clicked. However, I encountered an issue - if the same menu item is clicked twice, I need to remove the active class. Initially, I tried using jQuery's toggleC ...

PHP Ajax Image Uploading and Storage

Is there a way to effortlessly upload an image and save it in the uploads folder without any page refresh? Not only that, but can we also have the uploaded image displayed on the screen within a designated div section? Unfortunately, I seem to encounter a ...

How to effectively filter nested arrays within Mongoose Populate function

I received the following object from a Mongoose query: let systems = [ { "maxUserLevel": 1, "subsystems": [ { "sections": [], "name": "apple" ...

the key of the global variable object is not displaying as being defined

Currently tackling some old legacy code that heavily relies on JQuery, and I'm stuck at a critical juncture. It seems like the process begins with initializing vm.products in newView = new DOMObj(). Then comes the data call, where a worker iterates t ...

Configure webpack to source the JavaScript file locally instead of fetching it through HTTP

Using webpack.config.js to fetch remote js for Module Federation. plugins: [ new ModuleFederationPlugin({ remotes: { 'mfe1': "mfe1@http://xxxxxxxxxx.com/remoteEntry.js" } }) ], Is it possible to incorporate a local JS ...

Button for navigating to the previous slide on a Jquery slider

There appears to be an issue with the code on the previous button. When the user presses "previous" on the first slide, there is a momentary blank slider before the last slide appears. Is there a way to make this transition smoother? Thank you for your a ...

Navigating through property objects in Vue: accessing individual elements

I am a newcomer to Vue and after reviewing other questions on this platform, I am struggling to figure out how to pass an object to a child component and reference individual elements within that object. My goal is to have access to all elements of the obj ...

Sort through each individual column in the table

My table filtering code isn't working, and I need to add a status filter with checkboxes. Can someone guide me on how to proceed? var $rows = $('tbody > tr'), $filters = $('#filter_table input'); $filters.on("keyup", fun ...

Express.js allows users to define a parent root folder domain

My Express Node.js application is structured as follows: app.get('/', page.index); //Add new, edit and delete form app.get('/approval', page.approval); //Task to approve/reject the subordinate form app.get('/task', page.task ...

Simultaneously activate the top and bottom stacked components by clicking on them

One of my components has two child components, A and B. Component A is set to position: absolute and placed on top of component B like an overlay. Additionally, component A has a higher z-index. Both components have onClick events attached to them. My que ...

Let's discuss how to include the scrollTop option

I am new to coding and I need help adding a scrollTop margin of +100px to my code. The page already has some top margin but I can't seem to locate it. I'm also having trouble finding where the margin-top is being set in the JavaScript file. /*** ...

I have successfully converted an SQL Join query into JSON, but now I am unsure of how to interact with the

I recently ran an SQL Join on two tables and obtained the following results: _____People_____ name: "Jane" age: 35 job_id: 1 _____Professions_____ job_id: 1 title: "Teacher" "SELECT * FROM People INNER JOIN Professions ON People.job_id = Professions.job ...

Express.js not redirecting to Angular route, app not starting

I have the following setup in my node.js app.js: app.use('/', routes); app.get('some_api', routes.someApi); app.use(function (req, res) { res.sendFile(path.join(__dirname, 'public', 'index.html')); }); Additio ...

The latest update to the Server Stats code mistakenly changes the channel to "undefined" instead of displaying the total number

I've been working on a private bot for a specific server that displays server statistics and more. However, I've encountered an issue where every time a user joins or leaves the guild, the bot updates a channel with 'undefined' instead ...

Utilizing AngularJS to show content based on regular expressions using ng-show

With two images available, I need to display one image at a time based on an input regex pattern. Here is the code snippet: <input type="password" ng-model="password" placeholder="Enter Password"/> <img src="../close.png" ng-show="password != [ ...

Implementing a Response to an AJAX POST Request with Servlets

I have a unique situation where I need to validate a username input in a text box. The process involves sending the entered username to a server for checking if it has already been taken by another user. If the username is available, I want to change the b ...

Updating the image sources of a group of image tags with a predetermined list

Looking to update a series of image source references within a specific div tag. For example: <!-- language-all: lang-html --> <div id="Listofimages"> <img src="images\2page_img_3.jpg"> <img src="images\2page_img_3 ...