4

How to call $modal.open from controller in angular js. Previously in ui-bootstrap 0.1.0 dialog was there. Now in current version what is the privision to call your dialog.

in 0.1.0 it was just $dialog.dialog(); Then call to Dialog (); in Lib -

return {
  // Creates a new `Dialog` with the specified options.
   dialog: function(opts){
      return new Dialog(opts);
},

// creates a new `Dialog` tied to the default message box template and controller.
//
// Arguments `title` and `message` are rendered in the modal header and body sections respectively.
// The `buttons` array holds an object with the following members for each button to include in the

// modal footer section:

// * `result`: the result to pass to the `close` method of the dialog when the button is clicked

// * `label`: the label of the button
// * `cssClass`: additional css class(es) to apply to the button for styling

messageBox: function(title, message, buttons){
    return new Dialog({templateUrl: 'template/dialog/message.html', 
           controller: 'MessageBoxController', resolve: {model: {
      title: title,
      message: message,
      buttons: buttons
    }}});
}

Can any one know how to call $modal.open in 0.10.0 ?

1 Answer 1

6

Set a function to do open:(set template, controller, resolve)

function open() {

var modalInstance = $modal.open({
  templateUrl: 'myModalContent.html',
  controller: ModalInstanceCtrl,
  resolve: {
    items: function () {
      return $scope.items;
    }
  }
});

});

Set modal controller:

var ModalInstanceCtrl = function ($scope, $modalInstance, items) {

    $scope.items = items; 

});

And call it when you want:

open();

If you want to call from the template:

replace

function open() {

to

$scope.open = function() {  

and call

$scope.open()
Sign up to request clarification or add additional context in comments.

1 Comment

NB: if the template is in a file, it need to be in single quotes ('') in the resolve clause.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.