Carlos Cifuentes
AngularJS → Angular reference

$q in modern Angular

$q is no longer needed. Use native promises with async/await, or RxJS operators when you combine HTTP calls.

Before · AngularJS
$q.all([UserService.get(id), OrderService.list(id)])
  .then(function (results) {
    vm.user = results[0];
    vm.orders = results[1];
  });
After · Angular
forkJoin({
  user: this.userApi.get(id),
  orders: this.orderApi.list(id),
}).subscribe(({ user, orders }) => {
  this.user.set(user);
  this.orders.set(orders);
});

What changes

  • $q.all becomes forkJoin (observables) or Promise.all (promises).
  • $q.defer is almost never needed; return the observable or promise you already have.
  • firstValueFrom converts an observable into a promise when async/await reads better.

Migration tip. Native promises do not trigger a digest in the AngularJS side of a hybrid app. Keep $q inside legacy code until that screen is migrated.

Related

Planning a migration or a micro-frontend platform?

In a 20-minute call you describe your situation and I tell you how I'd approach it. If it isn't worth doing yet, I'll say so.

Message me on LinkedIn