AngularJS材质通过md-dialog发送数据到单独的控制器

时间:2018-10-11 19:22:32

标签: javascript angularjs angularjs-service angularjs-factory angularjs-material

我有一个带有用于员工查询的按钮的表单,该表单由md对话框处理。当有人单击按钮时,将运行此功能:

//Employee Lookup button
$scope.emplLookupButton = function(){

  mdDialogService.emplLookupDialog()
   .then(function(res){
     $scope.selectedEmpl = res;
     return $scope.selectedEmpl;
   }).catch(()=>{});

};

此函数调用一个工厂,我正在使用它作为服务:

angular.module('moduleNameHere').factory('mdDialogService', 
  function($mdDialog){

    let parentEl = angular.element(document.body);
    let employeeMain = '';

    function emplLookupDialog($event){
      return  $mdDialog.show({
        parent: parentEl,
        targetEvent: $event,
        templateUrl: '**template name here**',
        clickOutsideToClose: true,
        hasBackdrop: true
      }).then(function(res){
        employeeMain = res;
        return employeeMain;
      }).catch(()=>{});
   }   

   return {
     employeeMain: employeeMain,
     emplLookupDialog: emplLookupDialog
   };
});

这一切都很好。但是,在我的模板中,我为用户提供了单击雇员的功能,并将其值返回给父窗体。我想从md对话框中获取返回的数据,并将其设置为等于原始控制器中特定输入正在使用的模型。

我可以从工厂内的对话框中控制台记录数据,所以我知道它是从对话框控制器返回到那里的,但是我似乎无法将其从工厂中获取到原始控制器。

从原始代码块返回的数据不返回任何内容,大概是因为它在发送任何内容之前正在寻找返回值。为了解决这个问题,我尝试了以下方法:

$scope.userInputMain = {
  employee: mdDialogService.employeeMain
};

但这并不能带我到任何地方。我错过了什么?

0 个答案:

没有答案