Re: Caching values in service and browser refresh

Showing 1-1 of 1 messages
Re: Caching values in service and browser refresh Dan Doyon 6/28/12 2:40 PM

below I use query to get llist of messages, for saving I pass in a messageId when I call it.    

 .factory('FooSvc', function ($resource) {

        return $resource('../foo/messages/:messageId', { format: 'json' }, {

              'query' : { method: 'GET', isArray: false },

              'save' : { method: 'PUT', params:  { messageId:'@messageId'} },

        });

    })

-- controller snippet

     var somelist = Foo.query(); 

     foo.save({messageId: 123});

Am I missing something?


On Thursday, June 28, 2012 1:46:34 PM UTC-7, bsr wrote:
With the help of community and the tutorials, I learned how to use session to encapsulate data and inject into various controllers. Now, in my application, I am trying to cache a request like below

angular.module('myApp.services', ['ngResource']).
    factory('Play', function($resource, $routeParams){
        var Play = {
            resource: function() {
                return $resource('/api/Play/:_id', {} )
            } ,
            initplay: $resource('/api/Play/:_id', {} ).get({_id:$routeParams._id})
        };


        return Play
});

initplay is initialized correctly and I could share it across controllers. Now, if I navigate away to other views, it all works till I refresh the browser window. The problem is that in some views I don't keep _id as part of url anymore. Is this a bad practice, or how should I handle this.