You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Semantics of Arguments Passed to Constructor of Component #23463
[ ] Regression (a behavior that used to work and stopped working in a new release)
[ ] Bug report
[ ] Performance issue
[ ] 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
[ ] Other... Please describe:
Current behavior
In the URL: https://angular.io/guide/architecture-components
at the place where the "class HeroListComponent" is defined, the explanation for the semantics of passing the argument "private service: HeroService" to the constructor method is missing.
Someone coming from the OOP background, they think that it is just a formal parameter and expects it to be initialized with the instance of the object created with new operator.
Expected behavior
Looks like, in Angular, by virtue of specifying it as a formal parameter to constructor method it automatically does the following:
private service: HeroService;
constructor() {
service = new HeroService();
}
If this is the case, in case some parameters to be passed while constructing as HeroService(p1,p2,p3), how it is done when it can be done in the constructor() syntax.
Minimal reproduction of the problem with instructions
None
What is the motivation / use case for changing the behavior?
Not Applicable
Environment
Angular version: X.Y.Z
Browser: Not Applicable
- [ ] 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: Not Applicable
- Node version: XX
- Platform:
Others: Not Applicable
Someone coming from the OOP background, they think that it is just a formal parameter and expects it to be initialized with the instance of the object created with new operator.
Im pretty sure that most devs will recognize that the component is using constructor injection.
Looks like, in Angular, by virtue of specifying it as a formal parameter to constructor method it automatically does the following:
private service: HeroService;
constructor() {
service = new HeroService();
}
Not sure where did you got this idea from, but its incorrect. @trotyl already pointed out how parameter properties work.
Hi Trotyl/Jose,
Thanks for your clarifications.
I am still learning TypeScript. Now, I realize that I need to catch up with
TypeScript even deeper.
Regards,
--Sreenivasulu Saya
On Fri, Apr 20, 2018 at 2:39 PM, José Toledo Navarro < ***@***.***> wrote:
Someone coming from the OOP background, they think that it is just a
formal parameter and expects it to be initialized with the instance of the
object created with new operator.
Im pretty sure that most devs will recognize that the component is using
constructor injection.
Looks like, in Angular, by virtue of specifying it as a formal parameter
to constructor method it automatically does the following:
private service: HeroService;
constructor() {
service = new HeroService();
}
Not sure where did you got this idea from, but its incorrect. @trotyl
<https://github.com/trotyl> already pointed out how parameter properties
work.
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
<#23463 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/ACuFqn5hWXe85MbLQU57DUKWUX7eo1GNks5tqaXBgaJpZM4TdC1A>
.
Thank you for the original comment and clarifications re typescript experience. Given that this architecture doc is part of the introductory material, we'll look at making it more clear for those who are learning typescript and angular together.
Activity
trotyl commentedon Apr 20, 2018
This is normal TypeScript semantics, Angular was not involved at all.
jotatoledo commentedon Apr 20, 2018
Im pretty sure that most devs will recognize that the component is using constructor injection.
Not sure where did you got this idea from, but its incorrect. @trotyl already pointed out how parameter properties work.
sayasree commentedon Apr 20, 2018
jenniferfell commentedon Apr 21, 2018
Thank you for the original comment and clarifications re typescript experience. Given that this architecture doc is part of the introductory material, we'll look at making it more clear for those who are learning typescript and angular together.
jenniferfell commentedon Apr 21, 2018
docarea=architecture
filename=guide/architecture-components.md
5 remaining items
docs: clarify wording in architecture overview (#24481)
docs: refactor pipe example to use the HttpClient (#22741)
angular-automatic-lock-bot commentedon Sep 13, 2019
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.