sog
sog

Reputation: 171

How to call $modal.open in Ui-Bootstrap 0.10.0 from controller in angularjs

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 ?

Upvotes: 4

Views: 8031

Answers (1)

Chen-Tsu Lin
Chen-Tsu Lin

Reputation: 23214

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()

Upvotes: 6

Related Questions