angularlocal-storageangular-material2localforage

Using LocalForage with angular 4


I have a list of items (using angular material2) that can be toggled and when opened/closed I want to save the state in localstorage.

http://plnkr.co/edit/ckk4BCkNYNgNzJodW53t?p=preview

I have no clue why but [expanded] runs multiple times..

html

<md-expansion-panel class="panel"  (opened)="openPanel('a3')" (closed)="closePanel('a3')">

js

shouldBeExpanded(name: string) {
   let item = localStorage.getItem(name);
   return item;
}

Solution

  • This is not the most elegant solution but it does the job. By using ChangeDetectionStrategy.OnPush I can get the result I want.. but I will probably rework this later on and amongst other things I´ll update the solution to similar approach as @Nehal wrote.

    http://plnkr.co/edit/Q3daXShLOilqhUA4J7eo?p=preview