bohoffi / ngx-localstorage

An Angular wrapper for localstorage/sessionstorage access.
https://bohoffi.github.io/ngx-localstorage/
Apache License 2.0
36 stars 14 forks source link

Using ngxLocalStorage in sub module ... complains about lsValuePath not being a known property #32

Closed syska closed 3 years ago

syska commented 3 years ago

Describe the bug Simple test run of the ngxLocalStorage directive from https://bohoffi.github.io/ngx-localstorage/ -> Directive: <input type="text" id="txt1" ngxLocalStorage lsPrefix="demo" lsInitFromStorage="true" lsEvent="input" [lsValuePath]="['value']"/>

Just pasted into a component which in defined in a module called ParthnerSharedModule

Can't bind to 'lsValuePath' since it isn't a known property of 'input'.

To Reproduce Steps to reproduce the behavior:

  1. Add the module to app.module.ts.
  2. Use the above from the samples ...
  3. See error

Expected behavior I'm really lost or really stupid here ...

The errors goes away if I import the module in my sub module ...

But when accessing the site I get Error: NgxLocalStorageModule is already loaded. Import it in the AppModule only

So ...

I use the LocalStorageService in one of my services which works fine.

I most be missing something here ... I can't be the first one doing to ... Please let me know if you need more information.

bohoffi commented 3 years ago

Hi @syska thanks for reporting. It seems like you are the first one doing this.

I'll take a look into this as soon as I can.

syska commented 3 years ago

If needed let me know if you need a small repo of the issue.

Also, i should mention that some modules will be lazy loaded.

Thanks for the fast response.

syska commented 3 years ago

Hi @bohoffi

Just created a small repo: https://stackblitz.com/edit/angular-ivy-hdgjx6?

Maybe it's a simply thing, maybe something needs to be changed to support this.

This shows the issues with a module having a component that is using the directives.

This is my first stackblitz usage to repo an issue, hope it's usefull.

bohoffi commented 3 years ago

@syska I've published v3.2.1 which adds a .forChild() method when importing the module into (lazy-loaded) submodules.

syska commented 3 years ago

@bohoffi

Holy smokes your the man. That was an extremely fast fix 🥰🥰🥰

I will go tests it later today.

It was purely luck i wanted to find a local storage implementation, that handled error cases etc. ... Then sat this feature to remember state in forms ... That was on the road map for the project ...

Not sure what it's actually called, I haven't found any other packages that does this ... But not needed since it was here 😁

Thanks a million.