How to pass a function to angular ui bootstrap modal

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

$scope.isChosen = function(concept) {
    return $scope.$parent.isChosen(concept);
};

This works, but I would rather pass the function modally in the same way that functions are passed to directives. I tried to use the "allow" modal parameter to do this, but to no avail. Is it possible to enable a function for a modal, and if so, what is the syntax? If this is not possible, is there any other way to do this than to access the parent area?

Edit: here is a plunger trying to pass a method to a modal, it is a bit simplified, but it is what I am trying to do: http://plnkr.co/edit/eCjbZP

+4
source share
1 answer

When you define your modal, you must decide the following:

  // 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, in your modalCtr, you can enter isChosen as follows:

  app.controller('modalCtrl',function($scope,isChosen){
     // now you can use your isChosen function however you want
  });
+6
source

Source: https://habr.com/ru/post/1544474/


All Articles