I am searching for a straightforward equivalent to join()
for threads in Angular.
In my Controller:
vehiclesService.getVehicles().then(function(sth){
$scope.vehicles = sth.data;
$scope.isend();//this call is not ideal
});
vehiclesService.getFitment().then(function(sth){
$scope.fitment = sth.data;
$scope.isend();//this call is not ideal
});
vehiclesService.getTagsList().then(function(sth){
$scope.tags = sth.data;
$scope.isend();//this call is not ideal
});
I want a way to trigger a function only when all 3 variables are initialized. The current method works, but I find it unsatisfactory. I have also attempted
$scope.$watch('vehicles', function() {
$scope.isend();
});
$scope.$watch('fitment', function() {
$scope.isend();
});
$scope.$watch('tags', function() {
$scope.isend();
});
$scope.isend = function(){
if($scope.vehicles !== undefined && $scope.fitment !== undefined && $scope.tags !== undefined)
alert('doSomething');
}
It works too, but I consider it even worse!
Is there a better approach to achieving this in Angular?