alekseyanikin2014-02-05 19:18:41
alekseyanikin, 2014-02-05 19:18:41

AngularJS: how to cache rendered views?

How to change the behavior of AngularJS, so that when switching between different views, they are not redrawn each time?

Answer the question

In order to leave comments, you need to log in

4 answer(s)
EugeneOZ, 2014-02-17

my request: https://github.com/angular/angular.js/issues/3825
experience: use ng-include

Ruslan Lopatin, 2014-02-05

What does "not redrawn" mean? If you just don't want to load the data from the server when the page opens, then just store the data in a service instead of loading it every time you build the controller.

Mykola Dzedzinskyi, 2014-02-05

You have to write your own ng-view directive to create such functionality.
The basic idea behind this is this:
Before changing routes, instead of destroying the current view, just store it in an invisible DIV cache, and unregister the scope listeners. Give the div element a data attribute with $$route.templateUrlto be able to get it back. Then load a new page and reload listeners.
Before changing the route, check the cache, and if your DIV page has a cache, get the element from the cache, re-register the scope and insert it into the current View cache.

rotorgames, 2014-08-20

Try this directive https://github.com/rotorgames/angular-rg-cache-view
It doesn't delete dom but caches it keeping scope and all events.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question