Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[bug report] Dragula service is provided multiple times instead of as a singleton #1082

Open
5 tasks done
RGunning opened this issue Jan 10, 2023 · 1 comment
Open
5 tasks done

Comments

@RGunning
Copy link

RGunning commented Jan 10, 2023

REQUIRED: Before filing a bug report

Change each [ ] to [x] when you have done it.

Describe the bug (required)

With v3 of this library, the DragulaService is provided multiple times instead of just when importing DragulaModule.forRoot().

  1. It is now providedIn: root https://github.com/valor-software/ng2-dragula/pull/1044/files#diff-845f2a393c0ade2f75831cff246267c8b1c96691d81d2d710c47f20eb14ef6d9R31
  2. provided on import of the DragulaModule imports: [DragulaModule] https://github.com/valor-software/ng2-dragula/pull/1044/files#diff-77b8912947381f081ed7f9efbc418716a1dcdfac9c5ebc2d5e6539cad507878fR8
  3. provided on calling DragulaModule.forRoot() imports: [DragulaModule.forRoot()]

As such it is easy to get inject the wrong instance of the DragulaService leading to incorrect behaviour. In my application I have a service (providedIn: Root) that injects the DragulaService. However, because it is providedIn root, since the v3 update it is now getting a different instance of the DragulaService to that injected into the DragulaDirective. As such calls of createGroup made in my root service are being ignored.

*** Expected:
importing DragulaModule does not provide an instance of the DragulaService and instead the DragulaService is either provided by providedIn: root or DragulaModule.forRoot(). My preferred solution would be to remove the forRoot and rely solely on providedIn: root, but this would be a breaking change.

Versions (required)

Please state which versions of the following packages you have installed:

  • @angular/core: 14.2.12
  • ng2-dragula: 3.2.0
@dino-laktasic
Copy link

I can confirm that I run into the same issue and it's definitely BUG. You should either provide DragulaService in root and remove it from providers list in DragulaModule and remove forRoot function or keep forRoot function and remove it from providers list in DragulaModule and remove providedIn from DragulaService service decorator. I tried fixes locally and they were working as expected.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants