Skip to content

Angular directive that act as a *ngIf with cached view.

License

Notifications You must be signed in to change notification settings

vlafranca/ngx-cache-if

Repository files navigation

ngx-cache-if

This directive to fill the gap between legacy *ngIf structural directive and [hidden] directive. ngxCacheIf will behave like a ngIf for the first rendering then will act has hidden/shown directive. This allow to render a component only when needed and keep it's result in cache if we need to hide it again. (conditionnal content).

Tested with :

Framwork Version
Angular 5 +
Ionic 3
    npm i --save ngx-cache-if

import NgxCacheIfModule in your app module.

    <my-comp async *ngxCacheIf="state"></my-comp>

Demo

Url : https://mkligknn.github.stackblitz.io StackBlitz : https://stackblitz.com/edit/ngx-cache-if

ngxCacheIf content loaded only once

*ngIf

By default ngIf diretive render the component each time you want to display it. And destroy it when you hide it. This cause the lifecycle events to trigger multiple time if you display the same content. (An async call made in ngOnInit for example).

ngIf content loaded each time

[hidden]

The hidden/shown behaviors renders the element at the rendering of the parent component and hide or display it with css. This cause the lifecycle events to be triggered at the rendering of the parent view. If you have multiples components to load in the same view that can cause a large amount of operations if they are computing all at the same time instead of rendering only when needed.

hidden content loaded at loading time

Run project

npm install ng build ngx-cache-if ng serve Will serve you a test case that demonstrate the use of the directive with a setTimeout.

About

Angular directive that act as a *ngIf with cached view.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published