Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
How to avoid calling this method twice?
Message
From
05/12/2014 04:39:34
 
General information
Forum:
Javascript
Category:
Other
Miscellaneous
Thread ID:
01611738
Message ID:
01611886
Views:
47
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.....)
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform