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.