Issue with Angular JS modal display issue

I am currently learning how to implement Modals in my AngularJS application using Bootstrap 4 framework. I have successfully managed to display the modal, but it is not appearing correctly - it seems to be blocking other components in the background and will not show if animation: true is set. I have included both ngAnimate and ui.bootstrap in my app controller, so I'm not sure what could be causing this issue.

Versions of Angular and ui-bootstrap used:

  • Angular v1.6.4
  • UI-bootstrap v2.5.0

Below, I will share the relevant code snippets:

View.html

<div class="container-fluid content-container" ng-app="listEmployee">
<div class="change-password-modal-container"></div>
  <script type="text/ng-template" id="myModalContent.html">
    <div class="modal-header">
        <h3 class="modal-title" id="modal-title">I'm a modal!</h3>
    </div>
    <div class="modal-body" id="modal-body">
        <ul>
            <li ng-repeat="item in ctrl.items">
                <a href="#" ng-click="$event.preventDefault(); ctrl.selected.item = item">{{ item }}</a>
            </li>
        </ul>
        Selected: <b>{{ ctrl.selected.item }}</b>
    </div>
    <div class="modal-footer">
        <button class="btn btn-primary" type="button" ng-click="ctrl.ok()">OK</button>
        <button class="btn btn-warning" type="button" ng-click="ctrl.cancel()">Cancel</button>
    </div>
  </script>
  ... <!--other html elements -->
</div>

Here is the snippet from my controller that pertains to displaying the modal:

Controller.js

var ctrl = this;
    ctrl.items = ['item1', 'item2', 'item3'];
    ctrl.animationsEnabled = false;
    ctrl.open = function (size, parentSelector) {
        var parentElem = parentSelector ? 
          angular.element($document[0].querySelector('.change-password-modal-container ' + parentSelector)) : undefined;
        var modalInstance = $uibModal.open({
          animation: ctrl.animationsEnabled,
          ariaLabelledBy: 'modal-title',
          ariaDescribedBy: 'modal-body',
          templateUrl: 'myModalContent.html',
          controller: 'ModalInstanceCtrl',
          controllerAs: 'ctrl',
          size: size,
          appendTo: parentElem,
          resolve: {
            items: function () {
              return ctrl.items;
            }
          }
        });
        modalInstance.result.then(function (selectedItem) {
          ctrl.selected = selectedItem;
        }, function () {
          $log.info('Modal dismissed at: ' + new Date());
        });
  };

The z-index of my content is set to 1 in my CSS file:

mystyle.css

#content {
    z-index: 1;
}

Below is the screenshot when animation:false:

https://i.sstatic.net/1qZfd.png

And here is the screenshot when animation:true (where the modal appears to be hidden behind the screen):

https://i.sstatic.net/Pdodh.png

Any help on resolving this issue would be greatly appreciated.

Answer №1

Upon reviewing this particular issue on GitHub, it became evident that the issue stemmed from the transition between Bootstrap 3 and Bootstrap 4. The classes used in Bootstrap 4 differ from those in Bootstrap 3; for instance, .in in version 3 is now .show in version 4.

Following the suggestion provided by IdanCo in the discussion thread, which I have simplified below for better comprehension, resolved the problem at hand.

The necessary change involves modifying the class names within ui-bootstrap-tpls-###.js as indicated below:

'class': 'modal-backdrop',
'ng-style': '{\'z-index\': 1040 + (index && 1 || 0) + index*10}',
'uib-modal-animation-class': 'fade',
'modal-in-class': 'in'   //change this
'modal-in-class': 'show' //to this
});

if (modal.backdropClass) {
backdropDomEl.addClass(modal.backdropClass);
@@ -477,7 +477,7 @@
'ng-style': '{\'z-index\': 1050 + $$topModalIndex*10, display: \'block\'}',
'tabindex': -1,
'uib-modal-animation-class': 'fade',
'modal-in-class': 'in'   //change this
'modal-in-class': 'show' //to this
}).append(content);

if (modal.windowClass) {
angularDomEl.addClass(modal.windowClass);

This adjustment is anticipated to be beneficial to any individuals facing a similar challenge in the future.

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

Tips on resolving the '403 (Forbidden)' error when making a $http.get call to etherpad

[header][1] [header][2] While attempting to send a GET request to an Etherpad hosted on a different domain, the OPTIONS preflight request is successful, but the subsequent GET request returns a 403 status code. Interestingly, the request goes through whe ...

When using angular $resource.save for savings, the view is forced to redraw and reflow because of the collection watcher

One of the challenges I'm facing involves loading and storing a model using $resource in AngularJS. This particular model is an aggregate with nested collections, which are displayed in an HTML view using ng-repeat. The structure of the model looks l ...

I am looking to add some flair to my ID "checkimg" using JavaScript

JavaScript if ((valid1 && valid2 && valid3 & valid4 && valid5 && valid6 && valid7 && valid8)==1) { // include an image in the specified ID. document.formElem.next1.disabled=false; } else { docume ...

Is there a way to specify both a fixed width and a custom resizable length for a Spring <form:textarea /> element?

Despite extensive research, I have yet to find an answer to my specific problem. Within a model window, I have a textarea element: <div class="form-group"> <label for="groupDescription" class="col-sm-2 control-label"> Descripti ...

Creating Custom Styles with Polymer for <content> Elements

Seeking help with styling using the ::content selector and custom CSS properties. Any insight would be appreciated! To simplify, I have a Polymer component utilizing a content tag that will always contain a paper-input: <template> <style> ...

Implementing Vuejs 2: The guide to dynamically loading and executing a script tag javascript file within the DOM

I am currently working with Vuejs and facing the challenge of dynamically inserting script tags into the DOM to embed JWPlayer videos like this: <body> <!-- HTML content --> <script src="//content.jwplatform.com/players/KZVKrkFS-RcvCLj33. ...

Achieve overlapping divs using the Grid Layout

My objective is to have the div overlap the next row(s) without pushing them down when it increases in size. I attempted to use position: absolute; but this caused issues with the Grid Layout structure. Preserving the shape of the grid is crucial to me ...

Retrieve the content from an HTML table cell enclosed within a division tag

I am currently facing an issue where I need to extract the value from a specific div in order to proceed with the program. The value that I am trying to retrieve is '12345678'. <td id="TransaccionTesoreriaRetencionItems_NroComprobanteRete ...

Is it feasible in Vue to import an scss file with deep selectors into the scoped styles of a component?

Is it possible to extract a Vue component's scoped SCSS with deep selectors into a separate file and then import it back in? For example: // Main.vue <template> <div id="main"> <h1>Title</h1> <span>Text< ...

Completing Forms Automatically with AngularJS

Hello! I'm just starting out with ng and I need to make an autocomplete textbox that will initiate an AJAX call when the text is changed. The catch is that the minimum length required to trigger the AJAX call is 3 characters. However, once the user en ...

Link a timestamp to a datetime-local input using ng-model

My challenge is to display an <input type="datetime-local> field using the ng-model attribute to represent a timestamp: <input type="datetime-local" ng-model="object.value"> This is being achieved with: $scope.object.value = 1433109600000; ...

What methods can I use to maintain alignment across different screen sizes?

html, body { height: 100%; width: 100%; margin: 0; padding: 0; overflow: hidden; } .container { position: absolute; width: 100%; height: 100%; ...

Achieve filter dominance by implementing an AngularJS filter name override

In my AngularJS application, I have an array of data that is displayed using ng-repeat. The data is filtered and paginated based on user inputs, with the filtering criteria set by a function in the controller. What I'm looking to do now is override t ...

Recover information from an angular directive

I have developed a unique directive named my-tree, and I am utilizing this directive in a view named example-tree-view.html as illustrated below: <my-tree ng-model="sampleTreeView.listNodes" ... /> The controller for this view is called sampleTreeV ...

Implementing default header and footer with Angular's ui.router

When dealing with ui.router modules, I have identified three different methods for setting a default header and footer for every view: DEFAULT HEADER <CONTENT> DEFAULT FOOTER 1. Using ng-include - inserting your header/footer in the initial .html ...

The progress bar is visually enhanced with a border style that doubles as a background color

While experimenting with a jsfiddle to create an animated progress bar, I stumbled upon something peculiar. I had a single CSS rule applied to the progress tag: progress { border:2px solid #ccc; } Prior to adding this CSS rule, the progress bar looke ...

Animating Angular for particular conditions

My goal is to create unique animations for specific state changes in my AngularJS app. I found inspiration from this tutorial: https://scotch.io/tutorials/animating-angularjs-apps-ngview, which works well. However, I am aiming for the following animations: ...

Tips for designing interactive tooltips for images

Are there any alternative methods for adding multiple tooltips on top of an image in a more elegant way, without relying on image maps? Ideally, a solution involving jQuery would be great, but not essential. I am aware that image maps can be used for this ...

Stop elements from overextending within their parent container

I am facing an issue with two divs that are wrapped inside a container div. The bottom div contains a dynamically filled table, which determines the overall width of all the divs. On the top div, I want to display several small red blocks that need to tak ...

Manipulating the distinct look of the final element in an *ngFor loop

I am trying to enhance the appearance of the last line of controls generated by an iterator by making it disabled and somewhat invisible. Currently, my code is functioning well, as shown below. <div *ngFor="let item of data; let last = last;"> &l ...