Different version similar to the one offered by Maxim Shoustin
I liked the answer but the part that bothered me was the use of <script id="..."> as a container for the modal's template.
I wanted to place the modal's template in a hidden <div> and bind the inner html with a scope variable called modal_html_template
mainly because i think it more correct (and more comfortable to process in WebStorm/PyCharm) to place the template's html inside a <div> instead of <script id="...">
this variable will be used when calling $modal({... 'template': $scope.modal_html_template, ...})
in order to bind the inner html, i created inner-html-bind which is a simple directive
The AngularJS Bootstrap website hasn't been updated with the latest documentation. About 3 months ago pkozlowski-opensource authored a change to separate out $modal from $dialog commit is below:
OK, so first of all the http://angular-ui.github.io/bootstrap/ has a <modal> directive and the $dialog service and both of those can be used to open modal windows.
The difference is that with the <modal> directive content of a modal is embedded in a hosting template (one that triggers modal window opening). The $dialog service is far more flexible and allow you to load modal's content from a separate file as well as trigger modal windows from any place in AngularJS code (this being a controller, a service or another directive).
Not sure what you mean exactly by "using JavaScript code" but assuming that you mean any place in AngularJS code the $dialog service is probably a way to go.
It is very easy to use and in its simplest form you could just write:
$dialog.dialog({}).open('modalContent.html');
To illustrate that it can be really triggered by any JavaScript code here is a version that triggers modal with a timer, 3 seconds after a controller was instantiated:
function DialogDemoCtrl($scope, $timeout, $dialog){
$timeout(function(){
$dialog.dialog({}).open('modalContent.html');
}, 3000);
}
To make angular ui $modal work with bootstrap 3 you need to overwrite the styles
(The last ones are necessary if you use custom directives) and encapsulate the html with
Different version similar to the one offered by Maxim Shoustin
I liked the answer but the part that bothered me was the use of
<script id="...">
as a container for the modal's template.I wanted to place the modal's template in a hidden
<div>
and bind the inner html with a scope variable calledmodal_html_template
mainly because i think it more correct (and more comfortable to process in WebStorm/PyCharm) to place the template's html inside a<div>
instead of<script id="...">
this variable will be used when calling
$modal({... 'template': $scope.modal_html_template, ...})
in order to bind the inner html, i created
inner-html-bind
which is a simple directivecheck out the example plunker
inner-html-bind
directive:Open modal windows with passing data to dialog
In case if someone interests to pass data to dialog:
Demo Plunker
The AngularJS Bootstrap website hasn't been updated with the latest documentation. About 3 months ago pkozlowski-opensource authored a change to separate out $modal from $dialog commit is below:
https://github.com/angular-ui/bootstrap/commit/d7a48523e437b0a94615350a59be1588dbdd86bd
In that commit he added new documentation for $modal, which can be found below:
https://github.com/angular-ui/bootstrap/blob/d7a48523e437b0a94615350a59be1588dbdd86bd/src/modal/docs/readme.md.
Hope this helps!
OK, so first of all the http://angular-ui.github.io/bootstrap/ has a
<modal>
directive and the$dialog
service and both of those can be used to open modal windows.The difference is that with the
<modal>
directive content of a modal is embedded in a hosting template (one that triggers modal window opening). The$dialog
service is far more flexible and allow you to load modal's content from a separate file as well as trigger modal windows from any place in AngularJS code (this being a controller, a service or another directive).Not sure what you mean exactly by "using JavaScript code" but assuming that you mean any place in AngularJS code the
$dialog
service is probably a way to go.It is very easy to use and in its simplest form you could just write:
To illustrate that it can be really triggered by any JavaScript code here is a version that triggers modal with a timer, 3 seconds after a controller was instantiated:
This can be seen in action in this plunk: http://plnkr.co/edit/u9HHaRlHnko492WDtmRU?p=preview
Finally, here is the full reference documentation to the
$dialog
service described here: https://github.com/angular-ui/bootstrap/blob/master/src/dialog/README.mdQuick and Dirty Way!
It's not a good way, but for me it seems the most simplest.
Add an anchor tag which contains the modal data-target and data-toggle, have an id associated with it. (Can be added mostly anywhere in the html view)
Now,
Inside the angular controller, from where you want to trigger the modal just use
This will mimic a click to the button based on the angular code and the modal will appear.