2016-08-25 5 views
0

これは、表示するModalポップアップのコードです。私はコントローラの内部に関数を挿入する必要があります。ここでモーダルポップアップコントローラ内の関数を渡す方法。角モーダルサービスモーダルポップアップ内で関数を書く方法。 Orelse Modalのポップアップ内で新しいコントローラー機能を渡す方法

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; 
     }); 
    }); 
} 

これは、モーダルポップアップの内側に渡さなければならない機能です。コントローラの代わりに。 Apply manual関数は、サービスで記述された関数名です。別のコントローラの中で呼び出さなければなりません。他の解決策を提案してください。

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'); 
    } 
}; 

これはNG-テンプレートとして考えられているこの私のhtmlファイルの私のディレクティブ

.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; 
         }); 
        }); 
       }; 

       } 

       } 
       } 

です。

<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> 
+0

のようになります。次

<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> 

お使いのコントローラであなたを示唆しています? –

+0

あなたのコントローラー機能も見せてください! – Aravind

+0

angle-uiモーダルポップアップを使用できますか?もしそうなら、[link](https://embed.plnkr.co/6fx26BVrXu0ud8TkvrMq/) –

答えて

0

あなたの質問はまだわかりませんが、これはあなたの問題だと思います。

HTMLからは、モーダル内のボタンをクリックして実行するモーダルおよび書き込み機能を表示する必要があります。 uはあなたが `this.applyManualScale`内部のモーダルコントローラを必要と言うことを意味しています。この問題については

私は

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

ありがとうございますが、私はテンプレートファイルを参照しているng-templateを持っています。私はすべての作業をしているが、私はモーダルコントローラの中で自分の機能を宣言しなければならない。それだけでは機能しない。 – Jsrimac

+0

あなたの問題を簡単に理解するのに役立つHTMLを公開してください! – Aravind

+0

私は自分のhtmlファイルを新たに追加しました。これをチェックしてください。 – Jsrimac