Angularjs Meanjs如何将一个查询链接到不同的控制器
我有一个crud模块叫做article,另一个叫做Devices。我希望文章crud模块中的数据也在设备文章中。有人知道如何实现这一点吗Angularjs Meanjs如何将一个查询链接到不同的控制器,angularjs,model,mean-stack,meanjs,Angularjs,Model,Mean Stack,Meanjs,我有一个crud模块叫做article,另一个叫做Devices。我希望文章crud模块中的数据也在设备文章中。有人知道如何实现这一点吗 devicesApp.controller('DevicesController', ['$scope', '$stateParams', '$location', 'Authentication', 'Devices','$modal', '$log', function($scope, $stateParams, $location, Authentica
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();
这是我的文章查询
$scope.articles = Articles.query();
您不能(也不应该)像这样与控制器通信。
为了使此代码正常工作,物品和设备必须是工厂或服务
devicesApp.factory('Articles', function(){
return {
query: function(){
return {/*Your data here*/};
};
};
});
您的下一个最佳选择是通过事件在控制器之间进行通信。Article和Device是两个crud模块,因此我将使用工厂调用articles query?我当前可能/不工作的解决方案位于设备列表视图页面下我添加了articles controller,但它似乎没有调用任何东西。您是否制作了它们或是否有文档在什么地方?如果它们已经是工厂/服务,那么您的控制器中应该有它们的一个实例(您不清楚使用query()会遇到什么样的困难)。您能告诉我们query()函数是什么样子的吗?如果这些函数在某处查询服务器,那么它们可能是异步调用,但您的代码需要同步响应。希望query()返回一个承诺。若是这样,那个么您的代码应该是这样的:Devices.query().then(函数(数据){/*对数据做点什么*/});