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
docs: fix bug in code examples for downgrading a service #19371
Conversation
The service is indeed called |
If that is the case, the documentation is even more confusing, since it states the opposite here:
|
It is indeed somewhat confusing, because we never show how the service is registered in AngularJS. In both Angular and AngularJS there are two things that identify a registered service:
In Angular, it is common to use the class itself as the injection token: providers: [
{provide: MyClass, useClass: MyClass},
// or the shorthand:
MyClass
] This is possible, because Angular's injection system can accept any token as identifier. In AngularJS on the other hand, we only accept string identifiers as token. Thus you are forced to use two different things: a string (for the injection token) and a class (for the service) .service('myServiceId', MyServiceClass) It is common in AngularJS apps to chose a service name for the token (e.g. .service('user', class UserService { ... }) Hopefully that clears it up a bit. Feel free to update to clarify things (as long as the change is valid 😃). |
Ok, I changed the token name back to the original and added a note to explain the 'heroes' string. https://github.com/angular/angular/pull/19371/files#diff-33c8eb0a067223c3fbf3dd45ec689efdR783 |
Hi @gkalpak , sorry for off topic, I guess there're some different voices on #15319 (comment), may I know what is the expected validity for DI token now (or planned future)? |
4c50615
to
e59eb37
Compare
@trotyl Good point, the question is: After the 5.0 release will people be upgrading their app from 1.x => 4.x or 1.x => 5.x. Either way, the docs will have to be updated to reflect this, but that's beyond the scope of this PR. |
@trotyl, yes, things might change in future version. I am not sure what the current state is. |
@@ -5,6 +5,7 @@ import { Hero } from '../hero'; | |||
|
|||
@Component({ | |||
selector: 'hero-detail', | |||
providers: [HeroesService], |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why this change?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@gkalpak Without this change I get this error in the app I'm trying to migrate:
ERROR Error: Uncaught (in promise): Error: [$injector:unpr]
Unknown provider: heroesServiceProvider <- heroesService
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This example provides the service on the NgModule
. Providing it on the component too, will create a separate instance for the component (different than what the rest of the app is using). This is not what we want here (but might be what you want in your app).
To share the same instance of the service across components, put it on the providers
array of the NgModule
.
I modified the code and added some more description text to the readme. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the updates @bertyhell. Just a couple of comments for you.
aio/content/guide/upgrade.md
Outdated
|
||
Note that the 'heroes' string inside the factory refers to the AngularJS `HeroesService`. | ||
It is common in AngularJS apps to chose a service name for the token (e.g. heroes) | ||
and append the Service suffix to create the class name (e.g. heroesService) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you please change "class name (e.g. heroesService)" to "class name, for example heroesService
"? The reasons for changes are:
- We are trying to minimize parentheticals whenever we can.
- We're replacing i.e. and e.g. with "that is" and "for example" since people often confuse them.
- For consistency,
heroesService
should be in code font, thus the back ticks.
aio/content/guide/upgrade.md
Outdated
<code-example path="upgrade-module/src/app/ajs-to-a-providers/app.module.ts" region="register" title="app.module.ts"> | ||
</code-example> | ||
|
||
You can then inject it in Angular using it's class as a type annotation: | ||
Then use the service inside your component by injecting it in the component constructor using it's class as a type annotation: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it's --> its
I know this was already there, but since you're on the line, would you mind deleting the apostrophe?
@kapunahelewong Sorry for the long delay. I missed the email notification about your comments. |
Hi @bertyhell! This PR has merge conflicts due to recent upstream merges. |
1 similar comment
Hi @bertyhell! This PR has merge conflicts due to recent upstream merges. |
Hey @bertyhell, if you'd like to rebase, I'd be happy to approve :) EDIT: oh, and squash. |
77495e0
to
9b32232
Compare
@gkalpak are there any changes left on this from your point of view? |
aio/content/guide/upgrade.md
Outdated
@@ -778,16 +778,25 @@ delete them once the upgrade is over. | |||
It's also recommended to export the `heroesServiceFactory` function so that Ahead-of-Time | |||
compilation can pick it up. | |||
|
|||
<div class="l-sub-section"> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Change l-sub-section
to alert is-helpful
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Minor css change
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
a couple of minor comments. LGTM otherwise.
aio/content/guide/upgrade.md
Outdated
<div class="l-sub-section"> | ||
|
||
Note that the 'heroes' string inside the factory refers to the AngularJS `HeroesService`. | ||
It is common in AngularJS apps to chose a service name for the token, for example heroes, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
chose --> choose
for example heroes --> for example "heroes"
aio/content/guide/upgrade.md
Outdated
|
||
Note that the 'heroes' string inside the factory refers to the AngularJS `HeroesService`. | ||
It is common in AngularJS apps to chose a service name for the token, for example heroes, | ||
and append the Service suffix to create the class name, for example `heroesService`. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Service --> "Service"
Also, classes (or constructor functions) start with an uppercase letter (by convention). So HeroesService
, not heroesService
.
aio/content/guide/upgrade.md
Outdated
<code-example path="upgrade-module/src/app/ajs-to-a-providers/ajs-upgraded-providers.ts" title="ajs-upgraded-providers.ts"> | ||
</code-example> | ||
|
||
You can then add the service to Angular by adding it to the `@NgModule`: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would change "add the service" to "provide the service".
9b32232
to
b8a4277
Compare
@gkalpak this one is ready for another review |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
#19371 (comment) hasn't been fully addressed. Other than that LGTM.
b8a4277
to
99807c4
Compare
99807c4
to
c3997c9
Compare
This issue has been automatically locked due to inactivity. Read more about our automatic conversation locking policy. This action has been performed automatically by a bot. |
No description provided.