Created
July 20, 2015 20:24
-
-
Save jhines2k7/bcaa5011ad1a2d2df738 to your computer and use it in GitHub Desktop.
Simple Async Service AngularJS
This file contains 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('dep2', []) | |
.factory('ServiceTwo', function($q, $timeout){ | |
var timeStamp; | |
return { | |
getTimeStamp: function(){ | |
var defer = $q.defer(); | |
if(typeof timeStamp === 'undefined'){ | |
$timeout(function(){ | |
timeStamp = Date.now(); | |
defer.resolve(timeStamp); | |
}, 2000); | |
}else{ | |
defer.resolve(timeStamp); | |
} | |
return defer.promise; | |
} | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment