Meanjs如何一个查询链接到不同的控制器 [英] Meanjs How to link one query to a different controller

查看:101
本文介绍了Meanjs如何一个查询链接到不同的控制器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个CRUD模块称为文章和花药一个叫做设备。我想从文章污物模块中的数据是,可以在设备的文章。有没有人有一个想法如何实现这一点?

  devicesApp.controller('DevicesController',['$范围,$ stateParams','$的位置,认证,设备,$模式, $登录',
功能($范围,$ stateParams,$位置,身份验证,设备,$模式,$日志){
    $ scope.authentication =认证;
    $ scope.devices = Devices.query();

这是我的文章查询

  $ scope.articles = Articles.query();


解决方案

您不能(也不应该)像这样的控制器进行通信。
为了这个code工作,文章和设备需要的工厂或服务。

  devicesApp.factory('文章',函数(){
  返回{
    查询:功能(){
      返回{/ *您在这里的数据* /};
    };
  };
});

I have one crud-module called article and anther one called Devices. I would like the data from article crud-module to be also in Device article. Does anyone have an idea how to implement this?

devicesApp.controller('DevicesController', ['$scope', '$stateParams', '$location', 'Authentication', 'Devices','$modal', '$log',
function($scope, $stateParams, $location, Authentication, Devices, $modal, $log) {
    $scope.authentication = Authentication;
    $scope.devices = Devices.query();   

And here is my articles query

$scope.articles = Articles.query();

解决方案

You can't (and shouldn't) communicate with controllers like this. In order for this code to work, Articles and Devices need to be factories or services.

devicesApp.factory('Articles', function(){
  return {
    query: function(){
      return {/*Your data here*/};
    };
  };
});

这篇关于Meanjs如何一个查询链接到不同的控制器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆