SoFunction
Updated on 2025-04-09

angularJS modal box $modal instance code

1.Introduce $modal module

For example: ('ModalCtrl',['$modal' ,'$scope' , function($modal ,$scope ){ }]);

2. Execute modal box function

$ = function(type, size, id) { 
  $ = id; 
  var modalInstance = $({ 
    templateUrl: 'tpl/weichat_modulebaseinfo.html', //template:'html element template',    controller: 'EditModuleCtrl', // Initialize the modal range    size: size, //Size configuration    scope: 'A content with a scope modal usage ($modal will create a subscope of the current scope, scope is optional) defaults to $rootScope', 
    resolve: { 
      items: function() { 
        return $; //Transfer value to the modal box controller      } 
    } 
    background: '', //Control the background, true (yes) or false (no), the static background exists, but outside the modal window, the modal window does not close    keyboard: '', //When Esc is pressed, whether the modal dialog box is closed, default to ture    windowClass: '' //Specify a class and add it to the modal window 
  }); 
 
  (function(selectedItem) { //Return the function after the modal box is closed, and the selectedItem is the return value 
  }) 
} 

3. Create a modal box controller

('EditModuleCtrl', ['$scope', '$modalInstance', 'BookService', '$stateParams', 'items', function($scope, $modalInstance, BookService, $stateParams, items) { //Rely on modalInstance    //items is the value passed    $ = function() { 
      //Execute internal operation of modal box    } 
 
    $ = function() { 
      $($); //Close and return to the current option    }; 
    $ = function() { 
      $('cancel'); // Exit without performing any action    } 
  }]) 

The above is all the content of this article. I hope it will be helpful to everyone's study and I hope everyone will support me more.