Ken Ken - 8 months ago 37
AngularJS Question

How to see whether modal is open in Angular UI Bootstrap

I'm using Angular UI Bootstrap. If a modal is open, I'd like to display

. If it's not open, I'd like to display
. Is there a way to do this within the HTML?

I tried using the following code, but it's wrong:


Any thoughts on how to do this correctly?

Below the relevant code I'm using to trigger the modal:


<button ng-click="myForm.agreement()">

Code in Controller:

function ($location, $stateParams, $modal, $scope, $http) {
var myForm = this;
// . . .

myForm.agreement = agreement;

function agreement() {


templateUrl: 'views/agreement.html'


.opened is not a property its a promise you can hook onto from $

So, using their example, see here -

$scope.modalOpen = false;
$ = function (size) {
    var modalInstance =  ${
        animation: $scope.animationsEnabled,
        templateUrl: 'myModalContent.html',
        controller: 'ModalInstanceCtrl',
        size: size,
        resolve: {
            items: function () {
                return $scope.items;

    modalInstance.opened.then(function () {
        $scope.modalOpen = true;

    modalInstance.result.then(function (selectedItem) {
        $scope.modalOpen = false;
    }, function () {
        $scope.modalOpen = false;

You want to call the promises and then do whatever you need. .opened is a promise for when the modal opens, and .result is a promise for when the modal closes. So using this idea, you would use $scope.modalOpen as your boolean.