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

How to call $modal.openfrom controller in angular js. Previously in the ui-bootstrap 0.1.0 dialog box. Now in the current version, that person is to trigger your dialogue.

at 0.1.0 it was just $ dialog.dialog (); Then call 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 anyone find out how to call $ modal.open in 0.10.0?

+3
source share
1 answer

Set function to open: (install template, controller, enable)

function open() {

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

});

Install modal controller:

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

    $scope.items = items; 

});

And call it when you want:

open();

If you want to call from a template:

replace

function open() {

to

$scope.open = function() {  

and call

$scope.open()
+5
source

All Articles