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

Component: DynamicDialog NullInjectorError: No provider for NameService! #14730

Closed
Draganlazarev90 opened this issue Feb 6, 2024 · 5 comments
Labels
Resolution: Duplicate Issue has already been reported or a pull request related to same issue has already been submitted

Comments

@Draganlazarev90
Copy link

Draganlazarev90 commented Feb 6, 2024

Describe the bug

Having a module with a service in providers array. Create a parent component that opens a dialog component with a child component that uses the service provided in the module, gives NullInjectorError instead of inheriting the service instance from the module.

Environment

Primeng 17.5

Reproducer

https://stackblitz.com/edit/7qkchf?file=src%2Fapp%2Fdemo%2Fdynamic-dialog-example-demo.ts,src%2Fapp%2Fapp.module.ts,src%2Fapp%2Fdemo%2Fdemo.service.ts,src%2Fapp%2Fdemo%2Fdemo.module.ts,src%2Fapp%2Fapp.component.ts,src%2Fapp%2Fdemo%2Fdynamic-dialog-example-demo.html,src%2Findex.html,src%2Fapp%2Fdemo%2Ftest-child.component.ts,src%2Fapp%2Fdemo%2Fdialog.component.ts,src%2Fapp%2Fdemo%2Fdynamic-dialog-example-demo.scss

Angular version

17.0.5

PrimeNG version

17.5

Build / Runtime

Angular CLI App

Language

TypeScript

Node version (for AoT issues node --version)

18.18.0

Browser(s)

No response

Steps to reproduce the behavior

  1. Create a module with providers array and provide a service
  2. Create a parent component
  3. Create a dialog component that will be opened from the parent
  4. Create a child component nested in the dialog component, and have the child component use the service provided in the module

Expected behavior

The child component should use the instance from the module providers array. Was working in v15 and prior

@Draganlazarev90 Draganlazarev90 added the Status: Needs Triage Issue will be reviewed by Core Team and a relevant label will be added as soon as possible label Feb 6, 2024
@Draganlazarev90
Copy link
Author

Might be related to #14491

@Draganlazarev90
Copy link
Author

@mehmetcetin01140 @cetincakiroglu any update on this?

@cetincakiroglu
Copy link
Contributor

Related to #14491, duplicate issues for the same problem. Closing this one and adding #14491 to the milestone.

@cetincakiroglu cetincakiroglu added Resolution: Duplicate Issue has already been reported or a pull request related to same issue has already been submitted and removed Status: Needs Triage Issue will be reviewed by Core Team and a relevant label will be added as soon as possible labels Feb 12, 2024
@cetincakiroglu cetincakiroglu modified the milestone: 17.7.0 Feb 12, 2024
@cetincakiroglu
Copy link
Contributor

cetincakiroglu commented Mar 6, 2024

Hi,

After the investigation, we've found the issue caused by injection level difference. You're providing dialogService in the component level and demoService in the module level. Because of this, dialogService fails to find and inject DemoService. It works as expected if both of them are provided at the same level. That's why injecting the DemoService to the component.ts makes it work. Please see the example: https://stackblitz.com/edit/7qkchf-expefk?file=src%2Fapp%2Fdemo%2Fdemo.module.ts

To provide a better guide, we'll update the documentation of DynamicDialog and mention this use. Thanks a lot for reporting the issue!

@Draganlazarev90
Copy link
Author

Thanks a lot, that indeed solves the issue

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Resolution: Duplicate Issue has already been reported or a pull request related to same issue has already been submitted
Projects
None yet
Development

No branches or pull requests

2 participants