Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
How to avoid calling this method twice?
Message
De
05/12/2014 04:39:34
 
 
Information générale
Forum:
Javascript
Catégorie:
Autre
Divers
Thread ID:
01611738
Message ID:
01611886
Vues:
46
This message has been marked as the solution to the initial question of the thread.
>Tried the first approach but got into infinitive loop instead. I am not very comfortable with the second approach.
>
>I guess for now I'll be contend with 2 server hits (but no hits at all afterwards). I hope we will be able to re-design this form to use ui-views instead of the partial views as now. In the latter case the view will only be invoked when clicked on the tab.

How about this (based on Rick's modified service):
        var deferred = null;

        function getMetaData() {
 
            if (deferred !== undefined) {
                return deferred.promise;
            }

            deferred = $q.defer();
            if (service.metaData)
                deferred.resolve(service.metaData);
            else {
                service.inProcess = true;
                $http.get('/api/invoices/metadata')
                    .success(function (data) {
                        service.metaData = data;
                        service.inProcess = false;
                        deferred.resolve(data);

                    })
                    .error(function (data, status, header, config) {
                        deferred.reject(status);
                    });
            }
            return deferred.promise;
        };
(Tried this briefly. Seems to work - i.e. two results; one call to the server.....)
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform