2016-04-28 101 views
2

从不同的控制器打开模态弹出窗口。在关闭模式弹出窗口时,我会做一些事情,并且我想将数据传输到另一个填充UI网格的控制器,并绑定到$scope.searchResultsGridOptions角度刷新UI网格

在一个模式的结束,我做的::

$("#iConfirmationModal").on('hidden.bs.modal', function() { 
    $state.go('transaction.search.results', {}); 
    //I close all the modals 
    $uibModalStack.dismissAll(); 
    //I get the stored search criteria 
    var searchResultsParam = TransactionDataServices.getSavedSearchParams(); 


    //Using them I hit the web service again and get the data to reload the UI Grid 
    TransactionServices.getTransactionAdvSearchResults(searchResultsParam).then(function (result) { 

      //I got the result 
      console.log(result); 
      /Now I want to reload the grid with this data , but the grid scope object which binds to this , is in separate controller 
      searchResultsGridOptions.data = result; 
     }); 
    }); 

在DEFCtrl.js

getSearchResultsGridLayout: function (gridOptions, uiGridConstants, datas) { 
     gridOptions.multiSelect = false; 
     // gridOptions.data.length = 0; 
     // gridOptions.data = ''; 
     gridOptions.data = datas; 
     console.log("Grid Data "); 
     console.log(datas); 
     console.log(gridOptions.data); 
     angular.element(document.getElementsByClassName('grid')[0]).css('height', '0px'); 
     // console.log(datas.length); 
     return gridOptions; 
    } 

但如何将

ABCCtrl.js文件

所以我只在模式关闭时才更改数据?

剩下的时间它不应该刷新网格?

或者,

有什么办法当在模式关闭,而不是简单地回到使用$state.for(),看到以前未刷新数据的状态,我可以看到更新的资料?

回答

0

嗨我认为你不需要在“ABCCtrl”控制器中调用“TransactionServices.getTransactionAdvSearchResults()”,但你必须在“DEFCtrl”控制器中调用它。

您需要找到一种方法将“ABCCtrl”中提取的“searchResultsParam”传递给“DEFCtrl”。可以使用ui-router state parameters。您可以在 “transaction.search.results” 状态指定参数,如:

.state('transaction.search.results', { 
    ... 
    params: { 
     searchResultsParam: null 
    } 
    ... 
}) 

并在 “ABCCtrl” 它传递到状态:

$("#iConfirmationModal").on('hidden.bs.modal', function() { 
    //I close all the modals 
    $uibModalStack.dismissAll(); 
    //I get the stored search criteria 
    var searchResultsParam = TransactionDataServices.getSavedSearchParams(); 
    $state.go('transaction.search.results', {searchResultsParam: searchResultsParam}); 

然后,在“DEFCtrl “你可以阅读它并调用”TransactionServices.getTransactionAdvSearchResults()“方法。