Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

268
Views
equivalent of $q.when in angular 2

I am used to using $q with angular 1. I am migrating to angular 2.

Is there an equivalent that provide a .when() method ?

for example I need to migrate this:

.service('updateProDB', [
            '$rootScope',
            'connectionStatus',
            '$q',
            'storageService',
            'sendToServer',
            '$ionicPopup',
            function ($rootScope, connectionStatus, $q, storageService, sendToServer, $ionicPopup) {
                'use strict';

                var dbReadyDeferred = $q.defer(),
                prodata = [],
                prodataFieldNames = [];

            this.get = function () {
                var debugOptionUseLocalDB = 0,
                    prodata = [],
                    serverAttempts = 0;

                if (debugOptionUseLocalDB) {
                    return fallbackToLocalDBfileOrLocalStorageDB();
                }
                if (connectionStatus.f() === 'online') {
                    console.log("Fetching DB from the server:");
                    return getDBfileXHR(dbUrl(), serverAttempts)
                            .then(function () { // success
                                console.log('-normal XHR request succeeded.');
                                return dbReadyDeferred.promise;
                            })
                            .catch(function (){
about 4 years ago · Santiago Trujillo
1 answers
Answer question

0

You can do the equivalent, with:

Promise.resolve(promise).then

Which basically makes no distinction between promises and values.

And yes you can instantiate q the same way, but with new Promise() rather than $q()

let promise = new Promise((resolve, reject) => {
    if (/* some async task */) {
       resolve('Success!');
    } else {
        reject('Oops... something went wrong');
    }
});

and

let promise = $q((resolve, reject) => {
    if (/* some async task */) {
       resolve('Success!');
    } else {
       reject('Oops... something went wrong');
    }
});

They should be equivalent

about 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!