angular-strap icon indicating copy to clipboard operation
angular-strap copied to clipboard

Angularstrap Modal not show content when click open with $modal service twice

Open sangnv opened this issue 13 years ago • 12 comments

I found a problem in the overview and example of Modal popup. When I click the first time the modal popup is show the content correctly "Hello Modal", but when I click the second times the content was show wrong "{{modal.content}}". Can any one help me to fix this problem. Thanks in advance!

sangnv avatar Jun 01 '13 10:06 sangnv

Please provide a reproducible test-case from this working plunker: http://plnkr.co/edit/xKP5PW3Dco1CczmCuuVN?p=preview

Feel free to reopen when its done.

mgcrea avatar Jun 02 '13 11:06 mgcrea

I see the issue reproduced in the aforementioned plunker already, but only for the service button. The first time you click the "With $modal Service" button, you see "Hello Modal" and "2 + 3 = 5". If you click "Close" then click "With $modal Service" again, you see "{{modal.content}}" and "2 + 3 = {{ 2 + 3 }}".

sirbarrence avatar Jun 03 '13 15:06 sirbarrence

If I pass a new scope to $modal() every time - using $rootScope.$new() - I don't have the problem. If I pass my controller's $scope as the scope parameter to $modal() - as inside $scope.viaService() in the example plunker - it fails to bind to the template the second time.

sirbarrence avatar Jun 03 '13 15:06 sirbarrence

The problem is visible on the AngularStrap site: http://mgcrea.github.io/angular-strap/#/modal.

To reproduce: Click the With $modal service button twice.

Results:

  1. The modal expressions are not evalutated.
  2. The other button stops working.

dogweather avatar Jun 03 '13 19:06 dogweather

There is an option called persist that is visible from the source, without it the scope is destroyed.

            $modal.on('hidden', function (ev) {
                if (!options.persist)
                    scope.$destroy();
            });

protoze avatar Jun 05 '13 04:06 protoze

mgcrea...awesome job with Angular Strap!!

I just ran into the same issue...and it still seems to exists...and still reproducible on the main site.

Any idea on when it might get fixed?

Thanks

ljovner avatar Aug 26 '13 21:08 ljovner

I just ran into this also from the code on the main site. It took more than a couple clicks of the "With $modal service" button before it stopped working, but it did eventually. I wish I could say exactly what I did, but I was just playing around with those two buttons and I'm not sure how many times I clicked what before it stopped working. It also stopped the other button from functioning.

EDIT: Opening the plunker for modals from the main site also causes the issue. 2nd click of the button and it no longer works.

timgautier avatar Aug 27 '13 20:08 timgautier

I also have the same problem. My code example is below:

EngagementApp.directive('profileModal', ['$compile', 'Request', '$modal', '$q', function($compile, Request, $modal, $q) {

return {
    restrict : 'A',
    link : function(scope, element, attrs) {
        var modalPromise = null;
        element.bind('click', function(e) {
            e.preventDefault();
            scope.modal = {
                username : attrs.profileModal,
                url : main_site_url
            };

            modalPromise = $modal({
                template : '/templates/profile_modal.html',
                persist : false,
                show : false,
                backdrop : 'static',
                scope : scope
            });
            //console.log('Create Promise');
            //console.log(modalPromise);
            $q.when(modalPromise).then(function(modalEl) {

                modalEl.modal('show');
            });

        });

    }
};

}]);

ProdigyView avatar Sep 04 '13 18:09 ProdigyView

I have a similar problem when the modal is created using the service from a controller which is not on the root scope (e.g., a controller of a routing view): the modal content is not evaluated ({{1+1}} is shown as {{1+1}}). See this example: http://plnkr.co/edit/Ep5l2CLM4npjVSDP3c4d?p=preview

ericmedvet avatar Sep 23 '13 20:09 ericmedvet

Solved: the anchor in the plunker which triggers the modal opening via service should not have href="#".

ericmedvet avatar Sep 23 '13 21:09 ericmedvet

you should remove ng-show="title" , ng-show="content" or ng-bind="title" from the template. You should make sure that the template has no ng-show.

JavaBasketball avatar Oct 14 '15 07:10 JavaBasketball

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

lock[bot] avatar Jan 26 '19 02:01 lock[bot]