Issue with AngularJS function not being executed when ng-submit button is clicked

I am facing an issue with a bootstrap modal that contains a form. The submit button is not triggering a function defined inside my AngularJS controller. Despite being able to read and display data on the page, clicking the submit button does nothing except closing the modal. To troubleshoot, I am attempting to log a message when the submit button is clicked. Any help would be appreciated.

AngularJS:

var app = angular.module('myApp', []);

app.controller('supportController',
    function($scope, $http) {

        $scope.updateList = function() {
            console.log('updateList function invoked!');
        };

        $http({
            method: 'GET',
            url: ".../_api/web/lists/GetByTitle('DCO-%20IT%20Issue%20Tracker')/items?",
            headers: {"Accept": "application/json;odata=verbose"}
        }).then(function (data, status, headers, config) {
            $scope.tickets = data.data.d.results;
            $scope.tickets.map(ticket => console.log(ticket));

    }, function errorCallback(response) {
        console.log(response);
    });
});

HTML:

<div class="container" ng-controller="supportController">
        <div class="row">
            <div class="col-12">
                <button class="btn btn-secondary btn-block" data-toggle="modal" data-target="#myModal">Submit Issue/Request Ticket</button>
            </div>
        </div>
        <div class="row">
            <div class="col-12">
                <table id="searchTextResults" class="table table-striped">
                    <tr>
                        <th>Title</th>
                        <th>Network</th>
                        <th>Details</th>
                    </tr>
                    <tr ng-repeat="ticket in tickets">
                        <td>{{ticket.Title}}</td>
                        <td>{{ticket.Network}}</td>
                        <td>{{ticket.Details}}</td>
                    </tr>
                </table>
            </div>
        </div>
        <!-- The Modal -->
        <div class="modal" id="myModal">
            <div class="modal-dialog">
                <div class="modal-content">
                    <!-- Modal Header -->
                    <div class="modal-header">
                        <h4 class="modal-title">DISA Europe - EU34 Support Request</h4>
                        <button type="button" class="close" data-dismiss="modal">&times;</button>
                    </div>
                    <!-- Modal body -->
                    <div class="modal-body">
                        <form action="" method="POST" ng-submit="updateList()">
                            <div class="form-group">
                                <!-- <label>Title</label> -->
                                <div>
                                    <lable>Submitted By</lable>
                                    <div id="user"></div>
                                </div>
                            </div>
                            <div class="form-group">
                                <label>Title</label>
                                <div>
                                    <input type="text" class="form-control input-lg" name="title" id="title">
                                </div>
                            </div>
                            <div class="form-group">
                                <label>Network</label>
                                <div>
                                    <input type="text" class="form-control input-lg" name="network" id="network">
                                </div>
                            </div>
                            <div class="form-group">
                                <label>Details</label>
                                <div>
                                    <input type="text" class="form-control input-lg" name="details" id="details">
                                </div>
                            </div>
                        </form>
                    </div>
                    <!-- Modal footer -->
                    <div class="modal-footer">
                        <button type="submit" class="btn btn-primary" data-dismiss="modal">Submit</button>
                        <button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
                    </div>
                </div>
            </div>
        </div>
    </div>

Answer №1

It seems that there are a couple of adjustments needed in your template to ensure it functions correctly:

  • Make sure to enclose the

    <button type="submit">
    within the <form> tags

  • Take the action attribute out of the <form> element to avoid the default submission action which causes a page reload.

<form ng-submit="updateList()">
  // ...
  <!-- Modal footer -->
  <div class="modal-footer">
      <button type="submit" class="btn btn-primary" data-dismiss="modal">Submit</button>
      <button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
  </div>
</form>

Answer №2

By omitting the data-dismiss attribute from the submit button, we were able to successfully trigger the 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

Transferring a list from MVC ViewBag to JavaScript

I have a situation where I am passing a list of users from my controller to the view using the ViewBag. Now, I also need to pass this same list to the JavaScript on the page. One way I thought of doing this is by iterating through the list with a foreach l ...

Leveraging Node.js alongside a Spring backend

As I delve into a project involving React on the frontend and Spring on the backend (both running on the same machine), an interesting question arises. Given that Spring backend operates independently of Node, and the web browser is used to showcase the Re ...

Plugin for webpack that replaces a specified function with an alternative one

I'm currently working on a webpack plugin that has the ability to analyze code and replace a particular function with another function. Additionally, this plugin will make the new function accessible globally. class PluginName { constructor(local, ...

The angular bootstrap typeahead feature is experiencing issues when used with a dynamic list that is fetched through the ng

Currently, I am utilizing the typeahead directive in angular-bootstrap. My issue arises when a user changes the input; I aim to trigger an ng-change event to retrieve a list from the server and subsequently filter the results. Once accomplished, I want to ...

What is the best method for retrieving information from MongoDB and presenting it in a table with Node.js?

I'm struggling to understand how to retrieve data from mongodb and display it in an html/ejs file. I have a button in the html/ejs file that, when clicked, should show all the data from a mongodb database collection. While I've come across simil ...

Leveraging npm packages within a Meteor project through cosmos:browserify

Trying to implement Radium, a JavaScript library for inline CSS, by following the instructions located here. In my app.browserify.js file: Radium = require("radium"); Within package.json: "radium": "0.13.4" Upon attempting to utilize Radium in the app&a ...

Receiving Accurate JSON Data in PHP

As a newcomer to PHP, I have studied some examples and written a code to fetch data from a database. However, when the database is not found, I receive a text response. Can anyone advise on how to return a proper JSON response if the database is not found ...

Monitor the current playing status of a YouTube video across any webpage

I am interested in developing a web extension that can identify the playback status of all YouTube videos visited by a user. Upon researching the YouTube API, I discovered that it only allows access to videos that are embedded by me. In this case, I am not ...

Displaying a portion of a React functional component once an asynchronous function call has been successfully executed

I am currently using material-ui within a React function component and have implemented its Autocomplete feature. I have customized it so that when the text in the input field changes, I expect the component to display new search results. callAPI("xyz") I ...

Query by ObjectId attribute of a subdocument in Mongoose

I'm facing a challenge with the following query: Stuff.findOneAndUpdate({ status: 'open', ...query }, value, { new: true }); Here, query is defined as: { 'buyer.user': mongoose.Types.ObjectId(user._id) }; The Stuff model contains ...

Laravel Mix causes errors when running `npm run dev` and breaks the package

My nodejs package is built using ES6 features such as 'let', the spread operator (...) and default values for function arguments. However, when I run npm run production with Laravel Mix, an error message appears: ERROR Failed to compile with ...

Trouble with radio button selection in Pyppeteer, puppeteer, and Angular JS

I am struggling to select the 'fire' option in a radio button within a div element using Pyppeteer. Despite multiple attempts, I have not been successful. Here is the structure of the div with the radio button: <div _ngcontent-xqm-c396=" ...

Design a progress bar that advances in increments of at least two and up to a maximum of

My task involves managing a simple list. const [progressBar, setProgressBar] = useState([ { isActive: false, name: "step1" }, { isActive: false, name: "step2" }, { isActive: false, name: "step3" }, { isActive ...

Node API session functioning properly on Postman but experiencing issues in web browser

I am currently working on developing a node API for authentication purposes. The login session is created and stored successfully when tested in Postman. However, I am encountering an issue where it does not work in the browser. I suspect that the problem ...

What is the reason behind the browser permitting cross-origin POST requests but not PUT requests?

Let's consider a straightforward example of utilizing the XMLHttpRequest. The following code snippet functions correctly (you can verify in the network tab or by navigating your browser to http://requestb.in/yckncpyc) despite displaying a warning in ...

What is the process for creating a local repository for Node.js npm?

When it comes to the building process in node js, there are a few goals that need to be called: Begin by calling npm install, which creates a folder called node_modules and places all dependencies from package.json into it. [for UI development] Execute a ...

How to incorporate a Bootstrap Dropdown into ng-grid using AngularJS

I'm attempting to incorporate a dropdown box into the headerCellTemplate property of ng-grid. The columnDefs are set up like this: columnDefs: [{field:'dt', displayName:'Time', width:'**', cellFilter:'date:\ ...

I'm having trouble executing the straightforward code I discovered on GitHub

https://github.com/Valish/sherdog-api Upon downloading the sherdog-api, I embarked on installing node.js as a prerequisite for using this new tool, despite having no prior experience with such software. Following that, I opened up the command prompt and n ...

Show a different image with a matching title each time the page loads

I need help creating a JavaScript script that will display a random image from an array along with an associated title each time the page loads. Is there a way to do this without using an onload function placed in the body tag? Currently, my code relies o ...

Updating data in MongoDB with an expiration feature

Despite setting the expireAfterSeconds option to 60 in my Mongodb shell, my new entries in the unlock schema are not being deleted after 60 seconds. db.unlocks.ensureIndex( { "createdAt": 1 }, { expireAfterSeconds: 60 } ) Here is the structure of my Sche ...