The ng2 Bootstrap modal will not close unless the button has an onclick function attached to it

I have been working on creating a page that displays a list of items. Each item, when clicked, triggers a ng2-bootstrap modal to show detailed information about that specific item. However, I encountered an issue when attempting to use (click)="lgModal.show()" outside of the button element. The modal was not responsive to clicks outside the overlay or the little x button for closing. The only way to close the modal was by pressing the 'Escape' key. Here is an example of the code:

<li (click)="lgModal.show()" *ngFor="let item of Items"> {{ item }}
    <div bsModal #lgModal="bs-modal" class="modal fade" tabindex="-1" role="dialog" aria-labelledby="myLargeModalLabel" aria-hidden="true">
        <div class="modal-dialog modal-lg">
            <div class="modal-content">
                <div class="modal-header">
                    <button type="button" class="close" (click)="lgModal.hide()" aria-label="Close">
                        <span aria-hidden="true">&times;</span>
                    </button>
                    <h4 class="modal-title">Large modal</h4>
                </div>
                <div class="modal-body">
                    ...
                </div>
            </div>
        </div>
    </div>
</li>

Is there a way to remove the button and place the (onclick) function outside of it? Large modal

Answer №1

In order to properly close the modal, ensure you include the data-dismiss attribute.

Make the following modification:

<button type="button" class="close" (click)="lgModal.hide()" aria-label="Close">
                        <span aria-hidden="true">&times;</span>
                    </button>\

Replace it with:

<button type="button" class="close" (click)="lgModal.hide()" aria-label="Close" data-dismiss="modal">
                        <span aria-hidden="true">&times;</span>
                    </button>

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

Steps for customizing the text representation of an object:

In my reactive form component, I have an input control attached to a formGroup. Let's consider this object: {Id: 1, Text: "some text here..."}. Just like a select or dropdown menu, I want to display the 'Text' part in the input field but sub ...

Troubleshooting a problem in Angular with the BrightCove Player Loader

After diligently following the steps to integrate BrightCove player loader into my Angular 11 project: npm install --save @brightcove/player-loader I proceeded to import it in app.Module.ts and the specific module where I intended to utilize brightcovePla ...

Modifying browser.location.href Cancels AJAX Requests

I am facing an issue with my HTML page. I have a button that, when clicked by the user, updates the window.location.href to the URL of a text file. In order to ensure that the file is downloaded and not opened in the browser, the text file is served with C ...

Mastering the correct application of both Express's res.render() and res.redirect()

After implementing a res.redirect('page.ejs');, my browser is displaying the following message: Cannot GET /page.ejs In my routes file, I have not included the following code structure: app.get('/page', function(req, res) { ...

What is the best way to apply the CssClass "active" when clicking on a link

How can we update the cssClass of a link button on each click event, considering that the page refreshes every time? Currently, when I click on any LinkButton, the default behavior sets the cssClass to Plus LinkButton. ---index.aspx----------- <ul cl ...

Incorporate Typescript into specific sections of the application

I've got a Node.js application that's entirely written in JavaScript. However, there are certain sections of my app where I'd like to utilize TypeScript interfaces or enums. Is there a way for me to incorporate Typescript into only those s ...

Passing data between pages in Node.js

My current project involves creating a web service using node.js. In this setup, I am utilizing curl to send POST data to my index.js application. The index.js app processes the received data and I need it to then route the output to various pages based on ...

Setting up tsconfig.json to enable support for either string literals or string templates involves adjusting the compiler options

After utilizing swagger codgen with the typescript-aurelia template to create API code, I noticed that a significant amount of string literals were being used in the resulting code. Despite encountering errors when running the transpiler tsc from the comma ...

What steps should I take to eliminate the npm error from appearing in the protractor's logs whenever a spec fails?

I recently began using Protractor with Jasmine for testing an Ionic2 application. However, I have encountered two major issues that I have been unable to resolve despite extensive research: 1.)Whenever any of my specifications fail during testing, the err ...

I am struggling to comprehend the code for a PHP form that triggers a JS OnUpdate event, which then uses AJAX to retrieve data from MySQLi

I want to give a special thanks to Alon Alexander for providing the JS and AJAX code, even though I don't fully comprehend it. I am more comfortable using PHP/JS without jQuery, but I am struggling to make it function as intended. My current issue in ...

determining the user's position within the <s:select> element

I have a dropdown select tag in my code with a list of countries. I want the user's country to be auto-selected when they access the page. This is the JSP code snippet: <s:select name="dropdown" list="countries" listKey="value" listV ...

Exploring the .map() Method in ReactJS

Would it be feasible to integrate another Postgres database table into the current mapping displayed in this code? It would be ideal if it could be done using some sort of array function. {items.map(item => ( <tr key={item.id}& ...

In my Node.js/Express.js application, I have a directory that holds various images. Whenever I attempt to view these images via their URL, I encounter a 404 error message

In my Node.js/Express js project, I have the following folder structure: root ----bin ----controllers ----middleware ----models ----node_modules ----public --------images ------------test.png ----routes ----views I am currently trying to determine the cor ...

Invoke a method within a function triggered by the .call() method

Currently, I am developing an n8n node that essentially functions every time a specific event occurs. To facilitate this process, I have created an abstract class which is invoked by the n8n environment. However, there seems to be a limitation in calling ...

What is the best way to merge several fetchMore functions within Apollo?

Can Apollo run multiple fetchMores simultaneously? I have a complex hook that executes two queries and combines their results into a single array. This is how it looks: export const useDashboardState = (collection: string) => { // Getting parameters ...

What is the process for creating a parent container in which clicking anywhere inside will cause a child container (built with jQuery UI draggable) to immediately move to that location?

This is a rundown of tasks that I am struggling to code more effectively: When the bar is clicked anywhere, I want the black dot button to instantly move there and automatically update the displayed percentage below it. Additionally, when I drag the butt ...

When aggregating data using Mongoose expressions, Number, Boolean, and ObjectId types are not compatible

I am facing an issue with my query: const match: PipelineStage.Match = { $match: { deleted: false, provinceId: new mongoose.Types.ObjectId(req.params.provinceId), }, }; const query: PipelineStage[] = [match]; const c ...

What is the best way to indicate the region of a shape that intersects with another shape in

Picture yourself with an area and placing a camera lens or eye above it. What I'd like to do is create an eclipse on the area to show exactly what the lens or eye can see. So far, I have achieved this: https://i.sstatic.net/VHWc5.png You can interac ...

Having trouble retrieving files from an Angular2 service

I am facing an issue in creating an Angular2 service for downloading files from the server. I have a table where each record represents a single file. When clicking on a specific record, the download method is called: download(r: FileObject) { this.re ...

Disregard the Field File when utilizing jQuery validation

I have created a form with jQuery validation, but I am facing an issue where the file upload field is showing a message "enter no more than 3 characters." I believe this problem is due to the maxlength="3" property in the file field. How can I remove the ...