2015-02-10 31 views
1

我有一个网页,我已经实现了引导模态对话框。我想从模块对话框中的按钮单击主控制器中调用一个方法,我想将值传递给方法。我怎样才能做到这一点。Twitter引导模式从父控制器调用方法

+0

使用工厂,您可以通过控制器“共享”方法和属性。 – klauskpm 2015-02-10 19:37:46

回答

1

看看这个plnkr我创建:http://plnkr.co/edit/2VuKmVidfMpnkSigeips?p=preview

这是你如何创建一个模式对话框:

$scope.onClick = function() { 
     var modalInstance = $modal.open({ 
     templateUrl: 'content.html', 
     controller: 'ModalInstanceCtrl', 
     size: 'sm', 
     resolve: { 
      item: function() { 
      return $scope.item; 
      } 
     } 
     }); 

     modalInstance.result.then(function (returnedInput) { <-- This is where you expect the value passed to modalInstance.close(value). 
     $scope.test = returnedInput; 
     }, function() { 
     // dismissed with cancel button 
     }) 

    }; 

的想法是调用close(),当您按下OK:

$modalInstance.close($scope.myinput); 

将数据从模态对话框的控制器传回主控制器。

编辑: 我更新了plnkr,以显示如何在不关闭模式的情况下直接从模态中更改主控制器中某个项目的状态。本质上,你想调用模态中的某个方法来改变主控制器中对象的状态。

+0

感谢restassured !!!,在这里你实际上正在关闭模态对话框并返回到主页面,但我仍然希望在函数调用之后仍保留在模态对话框中。 '关闭'是由bootstrap给出的方法。我可以使用我自己的方法,因为我不希望我的模式被关闭。 – 2015-02-10 23:29:56

+0

我的编辑是否回答您的问题,还是您需要更多说明? – restassured 2015-02-11 00:50:07

+0

谢谢你放心。这看起来不错,让我尝试实现这一点。希望这能解决我的问题。我有一个全局根控制器说WrapperCntrl作为我的应用程序中的所有其他控制器的父项。这WrapperCntrl拥有我需要在我的应用程序中的常用功能。现在,我的父控制器说cntrlA,这是我的模态cntrlB的父。当我在我的模态上使用btn时,我想从我的cntrlA中调用一个方法,该方法将依次调用WrapperCntrl中可用的常用方法。我甚至需要传递参数 – 2015-02-11 17:26:21

相关问题