简体   繁体   中英

Angular UI modal POST

I'm trying to load angular-ui modal but I can't find any information how to pass POST parameters to specified templateUrl url?

    var options = {
        controller: 'ModalInstance',
        backdrop: true,
        scope: $scope,
        size: ( typeof $element.data('size') != 'undefined' ) ? $element.data('size') : 'sm',
        backdropClass: backdrop,
        templateUrl: 'some url',
        data: { // needs to be replaced | this one is not working.
            media_id: 59 
        },
        resolve: {
            element: function(){
                return $element;
            }
        }
    };

    $scope.instance = $modal.open( options );

If there is no any official ways, how can I do it without get parameters?

From the documentation mentioned here angular-ui directive documentation

templateUrl - a path to a template representing modal's content

which means it should be the url to a html file or <script type="text/ng-template"> which would be rendered as the content for modal window.

In case you want to pass some data to this template, refer the plunker example the documentation provides.

The relevant things to be noted in this example for passing data to modal template are explained below

controller: 'ModalInstanceCtrl',
size: size,
 resolve: {
        items: function () {
         return $scope.items;
        }
      }

1)controller : controller property specifies the name of the controller that controls the template(html to be rendered) 2)resolve: resolve property specifies the data that has to be injected into the above controller

So in the example the ModalInstanceCtrl is the controller that is in control of the template to be rendered and items property can be injected into this controller, in other words you can pass the data to the modal window template.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM