角JS决心下决心 [英] Angular JS resolve in a resolve

查看:99
本文介绍了角JS决心下决心的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的意思了决心决心是,我希望能够先解决用户,然后解决他所有的其他信息,如addressess,联系人,朋友。

What I mean by resolve in a resolve is that I want to be able to resolve the user first, and then resolve all his additional info, eg, addressess, contacts, friends.

我目前有:

.state('website', {
            url : '',
            abstract : true,
            resolve : {
                // Request the current signed in user >
                current_user : ['Auth', function(Auth){
                    return Auth.requestUser();
                }]
            },
            views : {
                'main' : {
                    templateUrl : 'template.html'
                }
            }
        })

我会喜欢做的是以下内容:

What I'll like to do is the following:

.state('website', {
            url : '',
            abstract : true,
            resolve : {
                // Request the current signed in user >
                current_user : ['Auth', function(Auth){
                    Auth.requestUser().then(function(){
                       // HERE I WANT TO RESOLVE OTHER RESOURCES
                       // WHAT WILL I RETURN HERE?
                    });
                }]
            },
            views : {
                'main' : {
                    templateUrl : 'template.html'
                }
            }
        })

我不知道这是可能的。

I'm not sure if this is possible.

推荐答案

您可以注入解析参数到其他的决心功能:

You can inject "resolved" parameters into other resolve functions:

resolve: {
  current_user: ['Auth', function(Auth){
    return Auth.requestUser();
  }],

  // "Svc" here is some service I assume you have to get friends, address, etc...
  friends: ["Svc", "current_user", function(Svc, current_user){
     // Svc.getFriends can return a promise or a value
     return Svc.getFriends(current_user);
  }],

  address: ["Svc", "current_user", function(Svc, current_user){
     return Svc.getAddress(current_user);
  }]
}

然后,在控制器的状态,你可以注入 CURRENT_USER 朋友地址作为参数:

.controller("WebsiteMainViewCtrl", function($scope, current_user, friends, address){
   // ...
})

这篇关于角JS决心下决心的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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