简体   繁体   English

Angular Modal Service如何在模式弹出窗口中编写函数。 Orelse如何在Modal Pop Up内部传递新的控制器功能

[英]Angular Modal Service how to write the function inside modal popup. Orelse How to pass a new controller function inside Modal Pop Up

This is the code for Modal pop up to show. 这是Modal弹出窗口显示的代码。 I have to insert the function inside the controller. 我必须将功能插入控制器内。 Here How to pass the function inside modal pop up controller. 这里如何在模态弹出控制器内部传递函数。

scope.show = function(ChartData) {
    ModalService.showModal({
        templateUrl: "scaleRecipePopUp.html",
        controller:function(){
            // Here i have to pass the function. 
        }
    }).then(function(modal) {
        modal.element.modal();
        modal.close.then(function(result) {
            scope.message = "You said " + result;
        });
    });
}

This is the function which i have to pass inside the modal pop up. 这是我必须在模式弹出窗口中传递的功能。 In place of controller. 代替控制器。 Apply manual function is the function name which is written in service. 应用手动功能是在服务中写入的功能名称。 Either it has to called inside a separate controller. 要么必须在单独的控制器内调用。 Please suggest some other solution. 请提出其他解决方案。

this.applyManualScale = function(){    
    if(scope.isAutoScale){
       scope.max[scope.idNum] = null;
       scope.min[scope.idNum] = null;
       scope.isAutoScaleArr[scope.idNum] = true;
       scope.plotDataSeries();
       $('#scaleModal').modal('hide');
    }
    else if(scope.maxVal!=null && scope.minVal!=null){
       scope.max[scope.idNum] = scope.maxVal;
       scope.min[scope.idNum] = scope.minVal;
       scope.isAutoScaleArr[scope.idNum] = false;
       scope.plotDataSeries();
       $('#scaleModal').modal('hide');
    }
};

This is my directive 这是我的指令

.directive('hcarea', function (Data, ModalService) {
    return {
        restrict: 'E',
        templateUrl: "../page/trendChart.html",
        scope: {
          options: '='
        },
        link: function (scope, element) {   
            var chart;
            scope.show = function() {
                    ModalService.showModal({
                        templateUrl: "scalePopUp.html",
                        controller:function(){
                        }
                    }).then(function(modal) {
                        modal.element.modal();
                        modal.close.then(function(result) {
                            scope.message = "You said " + result;
                        });
                    });
                };

                }

                }
                }

This my html file where it is considered as ng-template. 这是我的html文件,被认为是ng-template。

<script type="text/ng-template" id="modal.html">
     <div class="modal fade">
      <div class="modal-dialog">
        <div class="modal-content">
          <div class="modal-header">
            <button type="button" class="close" ng-click="close('Cancel')" data-dismiss="modal" aria-hidden="true">&times;</button>
            <h4 class="modal-title">Yes or No?</h4>
          </div>
          <div class="modal-body">
            <p>It's your call...</p>
            <p>Fry lives in {{futurama.city}}</p>
          </div>
          <div class="modal-footer">
            <button type="button" ng-click="close('No')" class="btn btn-default" data-dismiss="modal">No</button>
            <button type="button" ng-click="close('Yes')" class="btn btn-primary" data-dismiss="modal">Yes</button>
          </div>
        </div>
      </div>
    </div>
 </script>

Your question is not clear but still I guess this is your problem. 您的问题尚不清楚,但我仍然认为这是您的问题。

From a HTML you have to show a modal and write function which are performed in the button click inside the modal. 在HTML中,您必须显示模式和写入功能,这些功能可以在模式内部的按钮单击中执行。

For this problem I would suggest you with the following 对于这个问题,我建议您使用以下内容

 <div ng-controller="SampleController">
    <!--your HTML content-->
     <button class="btn btn-default"  data-toggle="modal" data-target="#myModal">
                  Button
     </button>
<!--Your modal content will be as below-->
<div id="myModal" class="modal fade" role="dialog">
  <div class="modal-dialog">

    <!-- Modal content-->
    <div class="modal-content">
    <div class="modal-header">
        <button type="button" class="close" data-dismiss="modal">&times</button>
        <h4 class="modal-title">Modal Header</h4>
    </div>
    <div class="modal-body">
        <p>Some text in the modal.</p>
    </div>
    <div class="modal-footer">
        <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
        <button type="button" class="btn btn-default" data-dismiss="modal" ng-click="ButtonClickMethod()">CustomButton</button>
    </div>
   </div>
 </div>
</div>

Your controller will look like 您的控制器看起来像

angular.module('myApp').controller('SampleController',
        function ($scope) {
            $scope.ButtonClickMethod = function () {
                    your logic goes here
            };
});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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