btford / angular-modal

Simple AngularJS service for creating modals

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Modal service "active" value not updated instantly

MarkusPint opened this issue · comments

Hello,
I like the module so far, however I am having a little problem with its' implementation.

  1. I have a main controller, where I am watching the modal service "active" value. This watcher changes a scope value in that controller in order to reflect in the view whether this modal is open or not.

    $scope.$watch( function() { return Modal.active(); },
    function(newValue) {
    $scope.ModalActive = newValue;
    }
    );

  2. In the controller of the modal I have a function:

$scope.closeModal = function() {
Modal.deactivate();
};
3. When this function is activated the modal does close, however the watcher in the main controller does not pick up the "active" value change.

I understand this is an async problem. A quick fix could be something with $timeout, but I am sure there is a more elegant solution. Any ideas?

Can you please provide a reproduction via jsbin, plnkr.co, or jsfiddle? This saves me a lot of time. Thanks!

This is expected behavior.

Each of these methods returns a promise that you can use to know when a state change finishes.