使用angular同步事件(如线程'join()'函数)

时间:2015-07-21 10:55:21

标签: javascript angularjs

我为线程寻找简单的select t2.*, (t2.qty - (select avg(t1.qty) from (select t1.* from table1 t1 where t1.prod = t2.prod and t1.reg = t2.reg and t1.od <= f2.fd order by t1.od desc limit 2 ) t1 ) ) as diff from table2 t2; 但是为角度。

在我的控制器中:

join()

我希望在初始化所有3个变量时调用函数。目前的工作。但在我看来这很难过。我也试试

vehiclesService.getVehicles().then(function(sth){
    $scope.vehicles = sth.data;
    $scope.isend();//this call suck in my mind
});
vehiclesService.getFitment().then(function(sth){
    $scope.fitment = sth.data;
    $scope.isend();//this call suck in my mind
});
vehiclesService.getTagsList().then(function(sth){
    $scope.tags = sth.data;
    $scope.isend();//this call suck in my mind
});

它起作用,但我发现它甚至最糟糕!

有角度的好方法是什么?

1 个答案:

答案 0 :(得分:2)

使用$q.all - 解决所有承诺后,将解决返回的承诺。

$q.all([
    vehiclesService.getVehicles(),
    vehiclesService.getFitment(),
    vehiclesService.getTagsList()
]).then(function(results) {
   // results is an array
   $scope.isend();
});