且构网

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

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

更新时间:2023-11-17 11:26:22

您应该使用$资源来获得$承诺如: resource.query()$承诺代替的 $ q.defer()清洁code。否则,你是好去。你可以使用 $ 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.

是不是与目前的code在当前状态下的共享变量?

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

我建议你看看 UI路由器及其嵌套的和抽象的观点,在解析值可供子控制器。

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