Tell me more ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

I'm new at Angular and am looking for some direction on how to proceed with loading a URL in an Angular Bootstrap modal. Would I be able to use the existing modal and go from there or am I looking at taking the code and writing a whole new directive?

share|improve this question
What do you mean by "URL"? – Michael Benford 9 hours ago
I mean that I would like to insert the result of an ajax call. I was thinking that I would open the modal with a spin load indicator then do my $http call and add the result to the inner content. Just not real clear on the full process though. – Yashua 8 hours ago
add comment (requires an account with 50 reputation)

put on hold as unclear what you're asking by leonm, Blade0rz, Pierre Fourgeaud, Carl Veazey, Radim Köhler 4 hours ago

Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking.If this question can be reworded to fit the rules in the help center, please edit the question.

2 Answers

There's no need to manually load the template into the dialog. The $dialog service from AngularUI accepts both a static template or a template url. That URL can return anything, it'll just perform a GET request via an AJAX call and fill the dialog with whatever data is returned. That request is cached locally so that next calls are supposed to be faster than the first one.

Here's a simple snippet to get you started:

Javascript

angular.module('app', ['ui.bootstrap.dialog'])
    .controller('Ctrl', function($scope, $dialog, $window) {
        $scope.open = function() {
            var options = {
                backdrop: true,
                keyboard: true,                    
                controller: 'DialogCtrl', // the dialog object will be inject 
                                          // into it
                templateUrl: 'path/to/view' // can be either a static file or 
                                            // a service that returns some data
            };
            var dialog = $dialog.dialog(options);
            dialog.open().then(function(result) {
                if (result === 0) {
                    $window.alert("Cancel pressed");
                }
                else if (result === 1) {
                    $window.alert("OK pressed");
                }
            });
        };
    })
    .controller('DialogCtrl', function($scope, dialog) {
        // Here you can put whatever behavior the dialog might have
        $scope.close = function(result) {
            dialog.close(result);
        };
    });

Main HTML

<div ng-app="app" ng-controller="Ctrl">
  <button ng-click="open()">Open dialog</button>
</div>

View HTML

<div class="modal-header">
  <h3>Title</h3>
</div>
<div class="modal-body">
  <p>Content</p>
</div>
<div class="modal-footer">
  <button class="btn" ng-click="close(0)">Cancel</button>
  <button class="btn btn-primary" ng-click="close(1)">OK</button>
</div>

This Plunker script demonstrates all of the above.

share|improve this answer
add comment (requires an account with 50 reputation)

"modal is a directive that reuses $dialog service to provide simple creation of modals that are already in your DOM without the hassle of creating partial views and controllers.

The directive shares $dialog global options."

Check the bootstrap dialog options below is the url :

http://angular-ui.github.io/bootstrap/#/dialog

share|improve this answer
add comment (requires an account with 50 reputation)

Not the answer you're looking for? Browse other questions tagged or ask your own question.