Content-Length: 391673 | pFad | http://github.com/angular/angular/pull/60809

9C docs: replace style guide with 2025 revision by jelbourn · Pull Request #60809 · angular/angular · GitHub
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

docs: replace style guide with 2025 revision #60809

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

jelbourn
Copy link
Member

@jelbourn jelbourn commented Apr 9, 2025

See RFC #58412 for background.

@jelbourn jelbourn added target: major This PR is targeted for the next major release area: docs Related to the documentation labels Apr 9, 2025
@ngbot ngbot bot modified the milestone: Backlog Apr 9, 2025
Copy link

github-actions bot commented Apr 9, 2025

Deployed adev-preview for 8fa50de to: https://ng-dev-previews-fw--pr-angular-angular-60809-adev-prev-uvdhn94r.web.app

Note: As new commits are pushed to this pull request, this link is updated after the preview is rebuilt.

Logic in a service can more easily be isolated in a unit test, while the calling logic in the component can be easily mocked.
See the Components guide for details
on [naming input properties](https://angular.dev/guide/components/inputs#choosing-input-names)
and [naming output properties](https://angular.dev/guide/components/outputs#choosing-event-names).
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
and [naming output properties](https://angular.dev/guide/components/outputs#choosing-event-names).
and [naming output properties](/guide/components/outputs#choosing-event-names).

Can we make all the adev links relative, this way they'll look as inner-links + they will keep you on the right subdomain (next or any future version the reader is on)

Copy link
Member Author

@jelbourn jelbourn Apr 9, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch, I forget to change the URLs after exporting from Google Docs (fixed)

@michael-small
Copy link
Contributor

Suggestion: mention the inject migration schematic.

@jelbourn jelbourn force-pushed the revised-style-guide branch from f93a57f to 8fa50de Compare April 9, 2025 22:53
* `inject` is generally more readable, especially when a class injects many dependencies.
* It's more syntactically straightforward to add comments to injected dependencies
* `inject` offers better type inference.
* When targeting ES2022+ with `[useDefineForClassFields](https://www.typescriptlang.org/tsconfig/#useDefineForClassFields)`, you can avoid separating field declaration and initialization when fields read on injected dependencies.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
* When targeting ES2022+ with `[useDefineForClassFields](https://www.typescriptlang.org/tsconfig/#useDefineForClassFields)`, you can avoid separating field declaration and initialization when fields read on injected dependencies.
* When targeting ES2022+ with [`useDefineForClassFields`](https://www.typescriptlang.org/tsconfig/#useDefineForClassFields), you can avoid separating field declaration and initialization when fields read on injected dependencies.

Fixes the output formatting


#### Style 05-16
Components and directives should group Angular-specific properties together, typically near the top
of the class declaration. This includes inputs, outputs, queries, and injected dependencies. Define
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since this isn't in alphabetical order, is the preferred order inputs, outputs, queries, injected dependencies, or is it unimportant? Perhaps we should state it either way?

<docs-code header="app/heroes/shared/hero-button/hero-highlight.directive.ts" path="adev/src/content/examples/styleguide/src/05-13/app/heroes/shared/hero-highlight.directive.ts"/>
<docs-code header="app/app.component.html" path="adev/src/content/examples/styleguide/src/05-13/app/app.component.html"/>
</docs-code-multifile>
Prefer using the `inject` function over injecting constructor parameters. The `inject` function works the same was as constructor parameter injection, but offers several style advantages:

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Prefer using the `inject` function over injecting constructor parameters. The `inject` function works the same was as constructor parameter injection, but offers several style advantages:
Prefer using the `inject` function over injecting constructor parameters. The `inject` function works the same way as constructor parameter injection, but offers several style advantages:


**Avoid** putting application logic in `main.ts`.
Instead, consider placing it in a component or service.
Separate words within a file name with hyphens (`-`). For example, a component named `UserProfile`
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As one of the motivations is to use more meaningful naming, I'd recommend promoting it by suffixing a component by the UI part it's related to, such as UserProfileHeader, UserProfilePage, UserProfileForm and so on.

UserProfile will more likely be used in this component as the main data type and would lead to conflicts.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
adev: preview area: docs Related to the documentation target: major This PR is targeted for the next major release
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants








ApplySandwichStrip

pFad - (p)hone/(F)rame/(a)nonymizer/(d)eclutterfier!      Saves Data!


--- a PPN by Garber Painting Akron. With Image Size Reduction included!

Fetched URL: http://github.com/angular/angular/pull/60809

Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy