如何在get方法完成后使用 this.getAllUsers 中的回调函数获取数据?
当我运行此代码 gitData 为空时
//REPOSITORY
$provide.factory('UsersRepository',["Repository",function(repository) {
this.route = '/api/mongoid_users';
this.getUsers = function(success_callback){
repository.get(this.route,success_callback);
};
return this;
}]);
//CONTROLLER
this.initGitData = function(urlData){
var gitData = {};
gitData = {
allUsers: ctrl.getAllUsers(urlData)
};
ctrl.getTypeRepository(gitData);
}
this.getAllUsers = function(urlData){
usersRepository.getUsers(function(users, status, headers, config){
});
};
答案 0 :(得分:0)
你的代码风格很混乱(对不起!)
如果声明service / repository方法,请使用promise样式等待返回结果:
//CONTROLLER
this.initGitData = function (urlData) {
ctrl.getAllUsers(urlData).then(function (result) {
var gitData = {
allUsers: result
};
ctrl.getTypeRepository(gitData);
})
};