Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
How to avoid calling this method twice?
Message
De
06/12/2014 06:57:05
 
 
Information générale
Forum:
Javascript
Catégorie:
Autre
Divers
Thread ID:
01611738
Message ID:
01611930
Vues:
33
This message has been marked as a message which has helped to the initial question of the thread.
>This seemed to work - I don't get 2 calls now.

You could drop the check on metadata. If you ever wanted to force a refresh you could add a parameter:
app.factory('invoicesService1', ['$http', '$q', '$timeout', function ($http, $q, $timeout) {

        var service = {
            metaData: null,
            getMetaData: getMetaData,
        }
        return service;

        var deferred = null;

        function getMetaData(refresh) {

            if (!refresh && deferred !== undefined) {
                return deferred.promise;
            }

            deferred = $q.defer();
            $http.get('/t2/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;
        };
    }])
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform