Skip to content

No results after implementing ProductService class #119

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

Closed
DanielRunningen opened this issue Jul 9, 2019 · 4 comments
Closed

No results after implementing ProductService class #119

DanielRunningen opened this issue Jul 9, 2019 · 4 comments

Comments

@DanielRunningen
Copy link

Hello,

I've been following along with the tutorial and have just completed Module 9, the section where our product list is separated form the component and initially hard-coded into the service. I've gone through the section a few times now and have not had success in getting the products to show up again.

At first I was having the issue NullInjectorError: No provider for ProductService!. I added the ProductService class to the providers of app.module.ts, which seemed to fix that issue, but I don't recall that being necessary from the tutorial, and the provided 'checkpoint' example for Module 9 doesn't have that line.

The issue following this, however, does not show any of the products in ProductService. This is also true when I compile directly from the example code from Module 9. No products are listed and no errors appear in the console. I'm not sure what I might be doing wrong?

Null Error
No Products

@DanielRunningen
Copy link
Author

Update as I was gathering info for this issue!

I went into my product.service.ts file to remove the product information (so putting it here would be less bulky) and lo and behold making a comment in the file fixed it.

The comment itself didn't fix it obviously, but causing an update in the product.service.ts file must have forced angular to update the reference to the class after fixing the null ref issue. So if you finish with Module 9 and have a similar issue, either restart the app or force an update to the service file and you should be fine.

Caching is a wonderful thing...

@DanielRunningen
Copy link
Author

Also good to note, you definitely do not need to have a providers line in app.module.ts if the products are now loading, so I'm still very confused, but it works lol

@DeborahK
Copy link
Owner

DeborahK commented Jul 9, 2019

Glad you were able to resolve the issue. Depending on the browser you are using, it is possible to turn caching off to minimize this issue.

Regarding the providers array, you should no longer need that. Services are now registered using the providedIn property of the @Injectable decorator. I cover this in detail in the "Services and Dependency Injection" module.

Hope this helps!

@DanielRunningen
Copy link
Author

@DeborahK - thanks, that's what I thought. Still not sure why adding it partially fixed the issue.

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

No branches or pull requests

2 participants