The Angular/Bootstrap Modal is not functioning properly: TypeError occurs due to v2.deleteModalProject not being recognized as a function and

My main objective is to allow users to call the modal multiple times for content deletion. However, I encountered issues when the modal was triggered a second time without reloading the page.

I am currently working with Angular version 1.5.6

After spending about two and a half hours searching online, I have tried various solutions but with no success. One of the attempts involved using a unique div with a random id generated through jQuery append, following an example from a stackoverflow post titled:

Twitter Bootstrap Modal Multiple event firing

Below is the HTML code snippet for my modal;

    <div class='modal fade' id='deleteModalProfile' role='dialog'>
      <div class='modal-dialog'>
          <!-- Modal content-->
          <div class='modal-content'>
            <div class='modal-header'>
              <button type='button' class='close' data-dismiss='modal'>&times;</button>
              <h4 class='modal-title'>{{modal.title}}</h4>
            </div>
            <div class='modal-body'>
              <p>{{modal.body}}.</p>
            </div>
            <div class='modal-footer'>
              <button ng-show='modal.project' class='btn btn-default' ng-click='removeProject()'>Yes</button>
              <button ng-show='modal.goal' class='btn btn-default' ng-click='removeGoal()'>Yes</button>
              <button type='button' class='btn btn-default' data-dismiss='modal'>No</button>
            </div>
          </div>

        </div>
      </div>

Here is the function that I'm struggling to prevent from being called twice;

     $scope.deleteModalGoal = function(goal, index) {
        $scope.modal = {"goal": true, "project": false, "title": "Delete Goal?",    "body": "Do you want to delete " + goal.task + " in " + goal.title + "?"}
        $scope.deleteModalGoalIndex = index;
        $scope.deleteModalGoal = goal;
        $("#deleteModalProfile").modal("toggle");
     }

This is the relevant section from my index HTML;

     <div ng-include="'views/modal.html'"></div>
     <button type="button" ng-click="deleteModalGoal(goal, $index)" class="btn btn-danger projectTaskDelete"> <i class="fa fa-trash"></i> Task </button>

I would appreciate any help or suggestions as I seem to have exhausted all possible options.

Thank you for your assistance, Daniel

Answer №1

"A second click triggers the error "TypeError: v2.myFunction is not a function," especially when the function shares the same name with a variable. The problem arises from Angular's $scope being overshadowed by a non-function variable.

To resolve the issue, I made a simple adjustment by adding an additional "s" to my function name.

The solution involved reassigning $scope.deleteModalGoals within the function $scope.deleteModalGoal instead of using $scope.deleteModalGoal = function()... This completely solves the problem.

https://github.com/angular/angular.js/issues/12353

Revised Code:

      $scope.deleteModalGoals = function(goal, index) {
    $scope.modal = {"goal": true, "project": false, "title": "Delete Goal?",    "body": "Do you want to delete " + goal.task + " in " + goal.title + "?"}
    $scope.deleteModalGoalIndex = index;
    $scope.deleteModalGoal = goal;
    $("#deleteModalProfile").modal("toggle");
 }

Original Code Snippet:

      $scope.deleteModalGoal = function(goal, index) {
    $scope.modal = {"goal": true, "project": false, "title": "Delete Goal?",    "body": "Do you want to delete " + goal.task + " in " + goal.title + "?"}
    $scope.deleteModalGoalIndex = index;
    $scope.deleteModalGoal = goal;
    $("#deleteModalProfile").modal("toggle");
 }

I hope this solution proves beneficial to someone facing similar challenges!

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

Check to see if a guest has shown support or followed an outside party

When you already follow a company on Twitter, the "Follow Us" button of that company will automatically turn grey, regardless of the domain. So, how can you determine if User-X is following companies A, B, and/or C based on their Twitter handles? The same ...

Automatically, the "ng-hide" class gets added despite using the correct syntax for ng-show

I am trying to dynamically show/hide a tr tag within a table based on the value of a scope variable in the controller. Despite writing the code correctly, I am facing an issue where the "ng-hide" class is automatically added to the tr tag every time it is ...

The use of HTML5 required attribute is ineffective when submitting forms via AJAX

Seeking advice on implementing basic validation for a newsletter form that only requires an email address. The current page layout doesn't allow space for jQuery error messages, so I attempted to use the HTML 5 required attribute. However, the form st ...

Tips on personalizing the FirebaseUI- Web theme

Can someone help me find a way to customize the logo and colors in this code snippet? I've only come across solutions for Android so far. if (process.browser) { const firebaseui = require('firebaseui') console.log(firebaseui) ...

Modifying a Field's Value by Referring to a Different Field

I am working on developing a form that includes a dropdown menu for changing the aircraft type. Additionally, I want to incorporate another field named "Registrations" which will automatically update the available registration options based on the selected ...

Is AngularJS not able to effectively manage the button type "reset"?

I currently have the following code snippet: <form name="editor"> <h2>Create/Update</h2> {{ editor.title.$error.required }} <div ng-class="{ 'has-error': editor.title.$invalid && editor.title.$dirty, &apo ...

Leveraging requestAnimationFrame in an Angular application

Currently, I am working on developing a directive that can animate a series of images, enabling the user to play, stop, and step through them. To ensure optimal performance, I am looking to leverage the requestAnimationFrame function. I came across a req ...

The value of req.body.stripeToken is not defined

I am facing an issue while using $http to post a form to my nodejs server. Upon posting, I attempt to retrieve the variable stripeToken using req.body.stripeToken in my server code, but it always returns undefined. Interestingly, when I make the post requ ...

Is there a way for me to determine which class has been selected using jQuery and JavaScript?

I created a list containing various links: <li class="link-1"><a href="#">One</a></li> <li class="link-2"><a href="#">Two</a></li> <li class="link-3"><a href="#">Three</a></li> .. Wh ...

The syntax of React Native's <{}> component structure

After using the command react-native init to create a new React Native project, I noticed that within the default template, the main component class is defined as follows: export default class App extends Component<{}> { ... } The <{}> par ...

What is the best way to assign classes to dynamically generated elements within a loop?

I have used a loop to create multiple components <li v-for="card in cardID" :key="card"> <app-profile class="profile" :id="cardID[i++]"></app-profile> </li> My goal is to wrap all these c ...

Is there a way to make the checkbox and corresponding text display on a single line within my code snippet?

Bootstrap text-truncate is causing the checkbox and text to appear on separate lines in the following example. How can I adjust it to have the text right after the checkbox? <!DOCTYPE html> <html> <head> <meta charset="UTF-8" / ...

Combining text shapes in Three.js without losing their distinct material colors

Currently experimenting with merging text geometries in Three.js (r84) and looking to achieve this using multiMaterial while preserving individual colors for each text object. Check out the live demo here: https://jsfiddle.net/5oydk6nL/ Appreciate any ins ...

Encountering problem while opening a PDF document in an AngularJS mobile application built with Cordova

Currently I am working on implementing the functionality to open PDF documents in AngularJS on desktop and mobile devices. I have been referring to the following resource: Open a PDF in a new window of the browser with AngularJS I have implemented a simila ...

Validating URL patterns in JavaScript using Ajax

Below are the ajax urls displayed in a specific format: http://example.com/v1/components/compId http://example.com/v1/machine/machineId http://example.com/v1/graph/startTime=value?endtime=value http://example.com/v1/graph/startDate=value?enddate=value? ...

Using class decorators in node requires the relect-metadata shim

After using Swagger Codegen to generate a TypeScript-Angular project and running npm install to build it, I proceeded to write a test class. Compiling it to JavaScript with tsc, I attempted to run the test class using node, only to encounter an error messa ...

Strategies for managing null JSON responses from the server

In my front-end application, there is a function that communicates with my node.js backend server: Client function: this.geocode = (placeName) => { const url = '/api/twitter/geocode?' + 'query=' + encodeURIComponent(placeName ...

Encountering TypeError: Unable to access the 'query' property as it is undefined

As I dive into learning AngularJS and sending requests to a Web API backend, I encountered the following error message: angular.js:13424 TypeError: Cannot read property 'query' of undefined In my project, I have a productListController define ...

determining if two words are synonymous or not

For this task, you are required to develop a program that can determine if two words are synonymous. A synonym dictionary will be provided with pairs of corresponding words. Your program will then need to respond to queries regarding whether two given word ...

The surprising margins that Bootstrap sneaks into columns

It seems like bootstrap is mysteriously including an unseen margin in my column classes. Even after inspecting an element labeled as 'col-lg-3,' there is no visible margin CSS, and attempting to manually add margin:0 still results in a margin bei ...