将angularjs网格数据从一个控制器暴露到另一个控制器

exposing angularjs grid data from one controller into another

本文关键字:控制器 一个 暴露 另一个 网格 angularjs 数据      更新时间:2023-09-26

我试图从我的网格数据UI中的链接推送数据,当你点击链接时,打开一个弹出窗口(我用模态罚款来做),但当模态打开时,我无法访问其他控制器中定义的任何数据。

这个片段:

    <a href ng-click="grid.appScope[col.field](row.entity)">Popup</a>

工作正常,它显示col.field值,但是我想在弹出窗口中显示来自grid.appScopecol.field的弹出窗口中的数据-但是那是另一个控制器,我如何处理在这种格式下从一个控制器向另一个传递数据?

我的建议是将这些数据传递到角度service中,定义一个类似的服务

angular.service('MyService', function() {
//if you want Object format or
this.controller1Data = {};
//if you want array format
this.controller1Data = {};
});

在你的控制器中,只需将数据传递到像这样的服务中

//In controller
MyService.controller1Data = //Pass the data to that service;

然后在HTMl 中

<a href ng-click="//call that method()">Popup</a>