Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

269
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda