Stacked and nested modals with ng2-bootstrap - a multi-modal experience!

I am facing an issue with a nested modal where the backdrop hangs behind the already opened modal. I have gone through the documentation and found ModalBackdropComponent with a selector of bs-modal-backdrop. However, I am unsure about how to specify the position of the backdrop to resolve this problem. I am not sure if this is due to a z-index conflict or if there is a specific placement required for the backdrop.

Answer №1

Encountered the same issue today and struggled to find a solution by defining my own instance of the bs-modal-backdrop component. What worked for me was setting [config]="{ backdrop: false }" on the bsModal element of the child modal to disable the default backdrop. Then, I inserted a new element like this:

<div class="modal-backdrop fade in" (click)="modal.hide()"></div>

This new element was added as the first child inside the child modal bsModal element. Assuming you have defined the modal property as #modal="bs-modal" or something similar. Another approach could involve calling a method on your component with the click handler.

Additionally, it may be necessary to assign a z-index of 1050 or above to the .modal-dialog element (a sibling of the new .modal-backgrop element).

Answer №2

When using ngx-bootstrap, there is limited control over the classes assigned to the modal container and backdrop elements. It seems impossible to insert a new element as a sibling of the .modal-dialog.

However, it is possible to style the nested/child modal containers individually. These containers are added to the DOM sequentially, allowing for CSS selectors such as :nth-of-type to target specific modal containers and customize their appearance, such as adjusting the background to create a faded effect.

.modal-container:nth-of-type(2) {
  background: rgba(0, 0, 0, 0.5);
}

Answer №3

Within the worldwide CSS file (styles.css):

modal-container+modal-container {
  background: rgba(0, 0, 0, 0.5);
}

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

Filtering through select options made easy with Bootstrap 4 in Angular

I am currently working on an Angular project and have integrated Bootstrap 4 into it. Within the project, I am utilizing a select element: <select> <option value="one">One</option> <option value="two">Two< ...

Setting up shortcuts for webpack using lerna and typescript

I have set up a repository to showcase an issue I am facing: https://github.com/vileen/lerna-webpack-typescript-aliases-issue (the app does not start properly, but that's not the main concern). The main question here is how can I enhance importing fr ...

The issue with functions not executing when triggered by HammerJS

In my application, there is a component that displays information for different days as they are cycled through using the functions dayUp() and dayDown(). Here is an example of how these functions are structured: dayUp() { if (this.dayCount == 7) { ...

Encountered a problem while executing the command (npm install -g @angular/cli) on a Mac

Encountering issues while trying to set up angular/cli on my system. When attempting to run the command npm install -g @angular/cli in the terminal, I encountered error messages. Even using sudo as a prefix did not yield positive results. npm ERR! Error ...

Passing Down Instance Methods Using Static References in JavaScript/TypeScript

✋ Exploring the concept of access modifiers from TypeScript, how can we make it relevant for JavaScript developers as well? Let's consider a scenario where a parent class defines necessary members and a shared method: // ParentClass.js export defaul ...

Angular - Is there a specific type for the @HostListener event that listens for scrolling on the window?

Encountering certain errors here: 'e.target' is possibly 'null'. Property 'scrollingElement' does not exist on type 'EventTarget'. What should be the designated type for the event parameter in the function onWindow ...

Add an image to a directory with Angular 7

I am having trouble uploading an Image to the assets/ folder using Angular 7. Below is my attempted solution: HTML: <form [formGroup]="form" (ngSubmit)="postData()" class="intro-form-css"> <div class="form-row"> ...

The issue of Angular Service Broadcast not functioning as expected when integrated with routing

When I subscribe to an event in Service, I am able to access the emitted data in another component. However, when I attempt to route the page, the data is being set in ngOnInIt() but after the routing process starts, it reverts back to its default state. T ...

The Art of Typing in TypeScript Classes

I am working with an interface or abstract class in TypeScript, and I have numerous classes that implement or extend this interface/class. My goal is to create an array containing the constructors of all these subclasses, while still ensuring that the arra ...

What is the proper way to conduct unit testing on a function that is invoked in a service's constructor

Is there a way to verify, within the service's spec file, that a function is invoked in the constructor? Consider the following example: @Injectable({ providedIn: 'root' }) export class myService { constructor() { this.myF ...

Deliver transcluded data to the descendant element of a hierarchical roster

I understand that there have been similar questions asked before, but my situation is slightly different. I am currently constructing a nested list and I want to include custom HTML content in each grandchild element alongside some common HTML. The problem ...

What is the best way to deactivate checkboxes in Angular 2?

Is there a way to prevent the user from checking a checkbox input? Is there an attribute like [enable] or [disable] to achieve this, or how can I ensure that the checkbox remains unchecked? <input type="checkbox" name="isActive" [(ngModel)]="user.isAc ...

NativeScript does not acknowledge the permission "android.Manifest.permission.READ_CONTACTS"

Hi there! I am a beginner in mobile development and currently learning Angular 2. I am facing an issue with requesting permission for reading contacts in NativeScript. It seems that "android" is not being recognized. For instance, when trying to execute t ...

Creating a file logging system with log4js to capture Console logs

Is there a way to automatically log all console logs, including failed expectations and exceptions, to a file without using try and catch in JavaScript? In Java's LOG4j, the rootlogger feature does this by default. Is there a similar functionality ava ...

Send the index of the row to the event handler in the table of data

I am currently utilizing a data table component from PrimeNG and have the following template code: <p-column [style]="{'width':'40px'}"> <template let-col let-rowData="rowData" let-rowIndex="rowIndex" pTemplate type="body" ...

Encountering an Angular 9 Ivy issue when using the <mat-form-field> with multiple mat-hints

After migrating to angular9 Ivy, I encountered an issue with multiple mat-hints in a single component. Before the update, my code looked like this: <div class="example-container"> <mat-form-field hintLabel="Max 10 characters" ...

Is it necessary to meticulously cycle through every value in the string combination?

So, I am working with a string union that looks like this: export type Intervals = 'total' | 'weekly' | 'biweekly' | 'monthly' | 'annually'; To show these options to the user, I plan on iterating over an ...

Unable to fetch QueryParameters in Angular 14

I recently developed a new Angular 14 application where I created a simple component named TestComponent. In the routing.module.ts file, I set up the following route: const routes: Routes = [{ path:'test', component: TestComponent }] The issue ...

Angular button press

Recently, I started learning Angular and came across a challenge that I need help with. Here is the scenario: <button *ngIf="entryControlEnabled && !gateOpen" class="bottomButton red" (click)="openGate()">Open</button> <button *ngIf ...

My Angular component seems to have a mind of its own, constantly refreshing itself and causing me

I'm facing an issue with a view that loads another component using routing. Here is the code that triggers the loading: <a href="/productDetails/{{product.ProductId}}">{{product.Name}}</a> Below is the div where the other component (prod ...