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

Heroes tutorial: adding service as described results in JS error #21085

Closed
conraddamon opened this issue Dec 19, 2017 · 5 comments
Closed

Heroes tutorial: adding service as described results in JS error #21085

conraddamon opened this issue Dec 19, 2017 · 5 comments

Comments

@conraddamon
Copy link

I'm submitting a...


[ ] Regression (a behavior that used to work and stopped working in a new release)
[ ] Bug report  
[ ] Feature request
[x] Documentation issue or request
[ ] Support request => Please do not submit support request here, instead see https://github.com/angular/angular/blob/master/CONTRIBUTING.md#question

Current behavior

While following the Heroes tutorial in chapter 6 (Services), an unexpected JS error is thrown: HeroService is not defined. That happens after "See it run" just before the tutorial moves on to "Observable data".

Expected behavior

No JS error.

Minimal reproduction of the problem with instructions

Follow the tutorial.

What is the motivation / use case for changing the behavior?

Environment


Angular version: X.Y.Z


Browser:
- [ ] Chrome (desktop) version XX
- [ ] Chrome (Android) version XX
- [ ] Chrome (iOS) version XX
- [ ] Firefox version XX
- [ ] Safari (desktop) version XX
- [ ] Safari (iOS) version XX
- [ ] IE version XX
- [ ] Edge version XX
 
For Tooling issues:
- Node version: XX  
- Platform:  

Others:

I'm just learning Angular 5, so sorry if I missed something. I believe the fix is to add instructions to import HeroService in app.module.ts, and to omit Message service from the providers list (until later in the tutorial).
@olbpetersson
Copy link

Did you include the HeroService in your providers-array of the app.module.ts?

@mattpenner
Copy link

Clarification:
The issue occurs in the Provide the HeroService section of the tutorial.

It states subtly to import the service:

Open the AppModule class, import the HeroService, and add it to the @NgModule.providers array.
[emphasis mine]

but never gives the example code on how to do so, which is confusing for beginners and inconsistent whereas most of the tutorial gives explicit example code for any necessary changes.

As also mentioned by the OP (separate issue?), the example code given for adding the HeroService to the providers array incorrectly adds MessageService, which isn't written until shortly later in the Create the MessageService section. This breaks the application throwing: error TS2304: Cannot find name 'MessageService'.

@gilessmart
Copy link

gilessmart commented Dec 26, 2017

Duplicate of #20398

@jenniferfell
Copy link
Contributor

Thank you. It looks like this issue was resolved. Issue #20398 shows the related commits. If this is still an issue, please let us know. Thanks again.

@angular-automatic-lock-bot
Copy link

This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.

@angular-automatic-lock-bot angular-automatic-lock-bot bot locked and limited conversation to collaborators Sep 13, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

6 participants