Skip to content
This repository has been archived by the owner on Apr 12, 2024. It is now read-only.

let $resource keep data until new response data has arrived #1737

Closed
konsultaner opened this issue Dec 20, 2012 · 2 comments
Closed

let $resource keep data until new response data has arrived #1737

konsultaner opened this issue Dec 20, 2012 · 2 comments

Comments

@konsultaner
Copy link

If you use the $resource service for getting data like a menu in combination with the $routeProvider service you need to request the data for the menu whenever the path changes, which causes the menu to blink.

It would be awesome if the $resource service would keep its data collected from the last request until the next comes in.

problem illustrated on jsFiddle: http://jsfiddle.net/4FfYb/3/

I had to solve the problem like this with an additional cache, which is probably not the right way to go, but it worked:

if ( angular.isArray( $scope.resourceObject)){
for(var i in cache){
$scope.resourceObject [i] = cache[i];
}
}else{
angular.extend( $scope.resourceObject ,cache);
}

@jtymes
Copy link
Contributor

jtymes commented Dec 20, 2012

Actually, I think using a caching strategy like you have is exactly how it should be done. It's trivial to manage this in your own code, so it's better to keep it out of the core of Angular, if possible to allow for flexibility. But that's just my opinion!

@pkozlowski-opensource
Copy link
Member

I share the @jtymes opinion here. On top of this I don't see much point of using $resource here, $http would be better suited for this (based on the attached jsFiddle and the problem description). And BTW $http supports caching.

Closing this for now, please seek the support on the mailing list if still need help.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants