How to pass a function to angular ui bootstrap modal

后端 未结 1 1569
悲&欢浪女
悲&欢浪女 2021-01-19 15:29

What is the best way to pass a function to an angular ui bootstrap modal dialog? I created a method in my modal controller that calls $scope.$parent.myMethod() like so:

相关标签:
1条回答
  • 2021-01-19 16:14

    When you are defining your modal , you must resolve like this :

      // here is the controller where you want to trigger the modal to open
     $scope.openModal = function () {
         // somewhere in your html , you may click on a button to envoke openModal()
       var modalInstance = $modal.open({
          templateUrl: 'myModalContent.html',
          controller: ModalInstanceCtrl,
          size: size,
          resolve: {
            isChosen: function () {
              return $scope.isChosen;
            }
         }
       });
    };
    

    And later on , in your modalCtr you can inject isChosen like this :

      app.controller('modalCtrl',function($scope,isChosen){
         // now you can use your isChosen function however you want
      });
    
    0 讨论(0)
提交回复
热议问题