SPEED & PERFORMANCE
Angular 2 is dramatically faster than Angular 1 with support for fast initial loads through server-side pre-rendering, offline compile for fast startup, and ultrafast change detection and view caching for smooth virtual scrolling and snappy view transitions.
The features look great, but a normal requirement is that when I navigate from ListComponent
to ViewComponent
, I want keep the ListComponent
cached so when I click back from ViewComponent
, the ListComponent
doesn't need to rerender(ListComponent
often gets AJAX data from page 2,3, etc. I know I can keep the data in a service and store the scrollPosition
when I click back, but it will rerender the data again. I really think caching it is a better way.
I implement CanReuse
, but it dosn't work, it only works when navigating between ViewComponents
. So., I want know how the ListComponent
to ViewComponent
caching can work.
Use the ProtoViewRef class:
Outer ProtoView:
Inner ProtoView:
References
Angular2 Issue #1492: Allow transplanting of <template> ProtoViews into other ViewContainers
Angular2 Issue #2529: Implement new content reprojection
Angular2 Issue #1351: Refactor DynamicComponentLoader/Compiler/Renderer to support user views and make them more consistent
Angular2 feat(core): add syntax sugar to make @View optional