且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

在 AngularJS 中的控制器之间共享数据

更新时间:2023-11-17 11:51:46

你应该使用 $resource 来获取 $promise eg: resource.query().$promise 而不是 $q.defer() 用于更清晰的代码.否则你很高兴去.您可以使用 $cacheFactory,但您也可以使用本地变量.

You should use $resource to get $promise eg: resource.query().$promise instead of $q.defer() for cleaner code. Otherwise you are good to go. You could use $cacheFactory, but you can also use local var.

您的共享变量是否处于当前状态并使用当前代码?

Isn't your shared variable in a current state with current code?

我建议你看看 ui-router 及其嵌套和抽象视图,其中解析值可用于子控制器.

I recommend you take a look at ui-router and its nested and abstract views, where resolved values are available to child controllers.