invoicesService.getMetaData().then(function (data) { $scope.invoicesMetaData = data; });So, I want to somehow adjust the service code to not invoke the method twice. Here is what I attempted to do but it's not working:
app.factory('invoicesService', ['$http', '$q', function($http, $q) { var metaData = null; var getMetaData = function () { if (angular.isObject(metaData)) return metaData; var deferred = $q.defer(); $http.get('/api/invoices/metadata') .success(function (data) { metaData = data; deferred.resolve(data); }) .error(function (data, status, header, config) { deferred.reject(status); }); return deferred.promise; };I still get 2 hits in my API controller. Do you see how should I change the above to avoid the second call after the first one was already made?