在不同模块上的控制器之间传递变量 [英] Passing variable between controllers which are on different modules

查看:68
本文介绍了在不同模块上的控制器之间传递变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我必须在不同模块上的角度控制器之间传递变量.服务是为此目的吗?有人可以举例说明吗?

I have to pass a variable between angular controllers which are on different modules. Are services meant for this? Can anyone explain with an example?

推荐答案

您将需要使用提供程序而不是服务.简而言之,注入服务将提供该服务的新实例,而注入提供程序将返回$ get(),因此您可以协调共享变量.

You will need to use providers rather than services. In a nutshell, injecting a service will provide a new instance of that service, whereas injecting a provider returns $get(), so you can coordinate shared variables.

这里有您要查找的内容的完整示例:使用AngularJS在模块之间共享?

There's a full example of what you're looking for here: sharing between modules with AngularJS?

这篇关于在不同模块上的控制器之间传递变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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