angularjs ng-click with boostrap's data-dismiss="modal"

22,465 views
Skip to first unread message

Leblanc Meneses

unread,
Apr 14, 2013, 5:56:09 PM4/14/13
to ang...@googlegroups.com

data-dismiss="modal" is bootstrap's way to dismiss a modal window


<button data-dismiss="modal" class="btn btn-primary" ng-click="AddWidget(SizeX,SizeY,Row,Column)">Add Widget</button>


Individually data-dismiss works to close modal window.

After adding ng-click to do work in my controller the modal window no longer closes.

Anyone know how to get these 2 attributes to work nicely together?

version: 1.0.5


clayton collie

unread,
Apr 15, 2013, 12:14:06 AM4/15/13
to ang...@googlegroups.com

vipin govind

unread,
Oct 9, 2014, 4:35:10 AM10/9/14
to ang...@googlegroups.com
use this inside ng-click function
$('#myModal').modal('hide');

Rahul Nair

unread,
Feb 17, 2015, 8:04:36 AM2/17/15
to ang...@googlegroups.com
Hi Leblanc
How did you resolve this issue?
Iam also facing the same.
Seek valuable help and support.
Thanks in Advance!

Gábor Imre

unread,
Mar 31, 2015, 5:49:15 AM3/31/15
to ang...@googlegroups.com
Hello all! 

I've met this problem when I wanted to use ng-enabled / ng-disabled on a modal close button.
See the 2 solutions below, each works: 
  • Cancel button with data-dismiss, no ng-disabled
  • Send button with ng-disabled, it closes the modal manually in a default onclick
The Send button would not work with the data-dismiss field. Nor would it work if the modal('hide') within the ng-click, I think it wouldn't work because of Angular's $scope. 

<div class="modal-footer">
<button type="button" class="btn btn-link notes-cancel-btn" data-dismiss="modal"
ng-click="ctrl.cancelEdit();">Cancel</button>
<button type="button" class="btn btn-primary"
onclick="$('.create-new-note').modal('hide')"
ng-click="ctrl.createNote()"
ng-disabled="bodyError()">Send!</button>
</div>

Note that this solution keeps the separation of concerns: The controller has nothing to know about the underlying HTML. 
One can also use some Angular+Bootstrap libs (as mentioned before by @clayton).

Regards, 
Gabor
Reply all
Reply to author
Forward
Message has been deleted
0 new messages