Last active
April 7, 2016 23:09
-
-
Save ibejohn818/3978c42a4dc594bfe8ba9c8fddb32e06 to your computer and use it in GitHub Desktop.
Angular aborting requests
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
| 'use strict'; | |
| angular.module('testServices',[]) | |
| .service('test',[ | |
| '$http','$q', | |
| function($http,$q) { | |
| var testing = function(ag) { | |
| console.log(ag); | |
| } | |
| var _userAccountsIndex = false; | |
| var _cancels = { | |
| }; | |
| var userAccountsIndex = function() { | |
| if(_cancels.userAccountsIndex) { | |
| _cancels.userAccountsIndex.resolve("CANCELED"); | |
| _cancels.userAccountsIndex = $q.defer(); | |
| } else { | |
| _cancels.userAccountsIndex = $q.defer(); | |
| } | |
| var req = $q.defer(); | |
| $http({ | |
| method:'GET', | |
| url:'/home/testing-service', | |
| data:{}, | |
| timeout:_cancels.userAccountsIndex.promise | |
| }).success(function(res) { | |
| req.resolve(res); | |
| }).error(function(res) { | |
| req.reject(res); | |
| }).finally(function(res) { | |
| delete _cancels.userAccountsIndex; | |
| }); | |
| return req.promise; | |
| }; | |
| return { | |
| testing:testing, | |
| userAccountsIndex:userAccountsIndex | |
| }; | |
| } | |
| ]); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment