0xAX
0xAX

Reputation: 21837

Angular-ui modal window opens only one time

I have angular application which uses angular-ui. I need modal window. My template of modal window:

<div modal="shouldBeOpen" close="close()" options="opts">
        <div class="modal-header">
            <h3>Create new entry</h3>
        </div>
        <div class="modal-body" ng-repeat="e in create_elements">
            {{e}}
        </div>

        <div class="modal-footer">
          ...
        </div>
</div>

and handler for open and close:

$scope.open = function(){        
    $scope.shouldBeOpen = true; 
}


$scope.close = function(){        
    $scope.shouldBeOpen = false; 
}

But it opens only 1 time, following clicking in open button doesn't do any effects. How to fix it?

Thank you.

Upvotes: 0

Views: 2392

Answers (2)

Priya Ranjan Singh
Priya Ranjan Singh

Reputation: 1567

I've created another attempt on jsfiddle w/ code similar to yours. It should be noted that clicking outside modal calls close() however I've included a button for clarity. Code pretty much stays the same.

http://jsfiddle.net/priyaranjan/dDjWe/

Markup

<div ng-app="myApp" ng-controller="myCtrl">
   <button class="btn" ng-click="open()">Open me!</button>
    <div modal="shouldBeOpen" close="close()" options="opts">
        <div class="modal-header"><h3>Create new entry</h3></div>
        <div class="modal-body">body</div>
        <div class="modal-footer">
            <button class="btn btn-warning cancel" ng-click="close()">Cancel</button>
        </div>
    </div>
</div>

JavaScript

angular.module('myApp', ['ui.bootstrap'])
    .controller('myCtrl',
        function($scope){

            // code from so post
            $scope.open = function(){
                $scope.shouldBeOpen = true;
            };

            $scope.close = function(){
                $scope.shouldBeOpen = false;
            };
        }
);

Feel free to checkout angular documentation for modal.

Upvotes: 0

Patrick
Patrick

Reputation: 8083

Created a plunkr with the solution: AngularJS Modal Dialog - plunkr

Works fine.

Upvotes: 0

Related Questions