Last active
April 16, 2016 10:58
-
-
Save abedsujan/a5a18ece69b71a7aee9ef4bfc8353a44 to your computer and use it in GitHub Desktop.
angularjs-client-side-caching
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
myapp.factory("movies", function($q, $http){ | |
var cacheMovies, p; | |
return { | |
getMovies: function(){ | |
return $q.when(cacheMovies || p || helper()); | |
} | |
} | |
function helper(){ | |
var deffered = $q.defer(); | |
p = deffered.promise; | |
$http.get("/movies").success(function(response){ | |
cacheMovies = response; | |
deffered.resolved(movies); | |
}); | |
retrun deffered.promise; | |
} | |
}); | |
// https://www.youtube.com/watch?v=33kl0iQByME | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment