Created
May 28, 2015 15:52
-
-
Save timelf123/f3b94a78ffdb7330e583 to your computer and use it in GitHub Desktop.
campaign service
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| angular.module('campaign', []) | |
| .factory('campaign', function ($log, $http, $q) { | |
| var self = this; | |
| this.campaigns = {}; | |
| // service logic | |
| this.getCampaign = function (groupName, productName, campaignShort) { | |
| self.apiEndPoint; // defined by env, ignore | |
| self.campaign = self.campaigns[campaignShort]; | |
| var deferred = $q.defer(); | |
| if (self.campaign) { | |
| deferred.resolve(self.campaign); | |
| } else { | |
| $http.get(self.apiEndPoint, { cache: true }).then(function(response) { | |
| if (angular.isObject(response.data)){ | |
| self.campaigns[response.data.shortName] = {}; | |
| angular.copy(response.data, self.campaigns[response.data.shortName]) | |
| deferred.resolve(response.data); | |
| } | |
| }) | |
| return deferred.promise; | |
| } | |
| }; | |
| return this; | |
| }); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment