Kaja Mca
Kaja Mca

Reputation: 11

service data should not remove , while refresh the page using angularjs

Please give the suggestion for above problem. any other way to pass the data to 2nd controller . and that one should not remove while refresh the page

      Thank you !!

Upvotes: 1

Views: 978

Answers (1)

Denis C de Azevedo
Denis C de Azevedo

Reputation: 6298

This data is in memory. If you refresh the page you will loose it.

You can use some approaches, like storing the data in your service in a cache, local storage, etc.

For example:

app.service("pojo", function() {
    var page1Data = getSavedData(); //A method to retrieve the data from a cache or storage
    this.setpgeCtrlScope = function(data) {
        page1Data = data;
        saveData(page1Data); //A method to save the data to the cache or storage
    }
    this.getpgeCtrlScope = function() {
        return page1Data;
    };
});

This way everytime the service is loaded (after a page refresh) it's going to retrieve the data previously saved.

Regarding the storage, there are a lot of options. This one is really easy to use:
HTML5 Local Storate

There are a myriad solutions and implementations for this. I gave you only one example to guide you.

Upvotes: 1

Related Questions