The presence of a modal within an ng-repeat directive leads to a system failure

Having trouble inserting a button inside a table that opens a modal? Each time you click the button, it seems to trigger multiple openings of the modal. The openModal and closeModal functions are defined within the main controller. Could the issue be related to using it within an ng-repeat loop? I'm not sure what's causing this problem. Can anyone point out my mistake? Here's the modal plugin being used:

http://angular-ui.github.io/bootstrap/#/modal

Check out the HTML code below:

<div class="row">
    <div class="span4" ng-repeat="court in courts"> 
      <table class="table table-condensed table-bordered table-hover">
        <caption><h4>court {{court.records[0].id}}<h4></caption>
        <tr>
          <th style='text-align:center'>Hour</th>
          <th style='text-align:center'>Player 1</th>
          <th style='text-align:center'>Player 2</th>
          <th></th>
        </tr>
        <tr ng-repeat="record in court.records">
          <td width="50" >{{record.hour}}</td>
          <td ng-style="user1Payed(record)" style='text-align:center'>{{record.u1_first}} {{record.u1_last}}</td>
          <td ng-style="user2Payed(record)" style='text-align:center'>{{record.u2_first}} {{record.u2_last}}</td>
          <td> <!-- options button -->
            <button class="btn" ng-click="openModal()">Open me!</button>
            <div modal="shouldBeOpen" close="closeModal()" options="opts">
                <div class="modal-header">
                    <h3>I'm a modal!</h3>
                </div>
                <div class="modal-body">
                    <ul>
                        <li ng-repeat="item in items">{{item}}</li>
                    </ul>
                </div>
                <div class="modal-footer">
                    <button class="btn btn-warning cancel" ng-click="closeModal()">Cancel</button>
                </div>
            </div>
          </td> <!-- options button end -->
        </tr> 
      </table>
    </div>
</div>

And here's the controller code snippet:

function CourtsController($scope, $window, $http, CourtsService, $timeout) { 
  $scope.openModal = function () {
    $scope.shouldBeOpen = true;
  };

  $scope.closeModal = function () {
    $scope.closeMsg = 'I was closed at: ' + new Date();
    $scope.shouldBeOpen = false;
  };

 $scope.items = [
            "Guest Payment",
            "Member Payment",
            "League (no payment)",
            "no Payment"
          ];

  $scope.opts = {
    backdropFade: true,
    dialogFade:true
  };

Answer №1

Adjust the position of your modal ng-repeat and update the $scope variable to match your openModal() function.

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

Get the first element of a 2-dimensional array after sorting it

In my possession is the following 2D array: [["fox", "100"], ["the", "1"], ["quick", "50"]] The task at hand is to keep only the first element of the array, but have it sorted based on the second ...

Styling the alert box with Bootstrap

My login error project utilizes the bootstrap alert to display errors. However, the issue I am facing is that when there is no error, it shows an empty box. Can someone help me figure out how to hide this div initially and only show it when an error occurs ...

Using protractor and AngularJS to extract text content from two labels by identifying the elements

My app is organized like this: <ul ng-repeat="variable in link.variables" ng-show="SearchboxCtrl.showData" class="ng-scope"> <li class="ng-binding"> Member Since: </li> <span class="ng-binding"> 2010-01-01 </span></ul& ...

Using JQuery to modify several background images in unison

I have a CSS code that uses 8 images to create a frame: background-image: url(images/blue/tl.png), url(images/blue/tr.png), url(images/blue/bl.png), url(images/blue/br.png), url(images/blue/t.png),url(images/blue/b.png),url(images/blue/l.png),url(images/b ...

Eslint requires that return values are used effectively

I am seeking a TypeScript or ESLint rule that enforces the usage of return values from functions. For example: const getNum = () => 12 This rule should allow me to call the function and store the returned value like this: const a = getNum() However, i ...

Ways to retrieve information from a JSON file and display it on a webpage using AngularJS

I am facing a challenge with my Angular controller where I am retrieving data from 2 different json files using a service and need to pass this data to a view. Here is a snippet of the controller file: .controller('MainController', ['info& ...

What is the best way to incorporate a line into a scene using three.js?

I am facing an issue with adding a line in three.js. When I call the addline function in my code, the line doesn't appear in the scene. I have tried to implement the MVC design pattern, but I am unsure where I went wrong. Thank you for any assistance ...

Angular is not yet able to identify the $resource framework

I have implemented ngResource into my app's module: angular.module('confusionApp', ['ui.router', 'ngResource']) Then, I added the $resource dependency to my service: angular.module('confusionApp') .consta ...

The optimal method to simulate a $http promise in this particular situation

I am trying to work with a factory function that directly returns an http promise. It is several layers deep, but I am only interested in mocking the success and error parts of it. This is what the code looks like: user.create() .success(function(res ...

Utilize the Multer file upload feature by integrating it into its own dedicated controller function

In my Express application, I decided to keep my routes.js file organized by creating a separate UploadController. Here's what it looks like: // UploadController.js const multer = require('multer') const storage = multer.diskStorage({ dest ...

Dynamic tables with a multitude of columns arranged in a grid

In this scenario, imagine I start with 2 tables: Categories Products Within the Categories table, there is a column called "No of products" that displays the number of products each specific category contains... Now, the Products table is grouped by Cat ...

I am using a Next.js app where users can upload images through an API, and the API returns the images to me in an array. I am trying to figure out how

Instead of using CKEditor to upload images, I have implemented my own API for image uploading. When a user uploads an image on my website, I make a call to the API to safely upload the image and return a URL in the Public Domain. The API returns the follo ...

Enable automatic dropdown menu activation on mobile browsers specifically tailored for Android devices

Is there a way to automatically trigger the opening of a combobox on Android device browsers? Here is the code I have: <!doctype html> <head> <meta charset="utf-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1"> ...

discord.js: Bot keeps sending duplicate embeds

I recently set up my discord bot to respond with a message when I enter a specific command, but I've run into an issue where it's sending the same embed twice. I've tried troubleshooting, but so far I haven't been able to pinpoint the c ...

Reasons for the failure of file uploads from the React frontend to the backend system

Recently, I embarked on a new project that involves using React for the front-end and Node for the back-end. The main requirement of this project is to upload multiple images from the front-end, with the back-end handling the file uploads to Cloudinary. I ...

Guide on adding an additional key:value pair to a sub document in a MongoDB collection

I'm facing difficulties trying to add a new key:value pair to an existing object in a MongoDB document. I've experimented with $each, $push, and $addToSet, but it seems like those are intended for arrays. I then attempted $set, but that only upd ...

Utilizing VUE with Socket.io or vue-socket.io Integration

I've been working on connecting using socket.io (client) and websocket.org (server) with vue.js. Despite going through all the examples, I can establish a connection to the socket but when I emit the event BOARD_ID, I don't receive any response. ...

Route Separation with ExpressJS and Socket.IO

As I delve into the world of ExpressJS and Socket.IO, I find myself facing a puzzling situation. My routes are neatly organized in a separate file that I include from my app.js: var express = require('express') , db = require('./db&ap ...

The Tooltip fails to display my content when hovered over for the first time, but it appears on the second attempt

Here is the code snippet: <a href="", class="cancel-invitation-from-other" title="Close" onmouseover = "show_bookclub_book_tooltip('Decline invitation','cancel-invitation-from-other');" data-placement="top"></a> and this i ...

Storing mySQL Database Content in a Javascript Array

I'm working on building a slideshow by fetching database information and storing it in a JavaScript array. Currently, I am using the jQuery AJAX function to retrieve data from a separate PHP file. Below is my PHP code: mysql_connect('x', &a ...