mirror of
https://github.com/angular/angular
synced 2026-05-24 09:28:37 +00:00
docs: update code block syntax highlighting in documentation & fixed identation
(cherry picked from commit b043c7490f)
This commit is contained in:
parent
15fd24d506
commit
3c417c7e56
14 changed files with 43 additions and 47 deletions
|
|
@ -26,7 +26,7 @@ For more information about this command, see [App shell command](cli/generate/ap
|
|||
|
||||
The command updates the application code and adds extra files to the project structure.
|
||||
|
||||
<docs-code language="text">
|
||||
```text
|
||||
src
|
||||
├── app
|
||||
│ ├── app.config.server.ts # server application configuration
|
||||
|
|
@ -36,7 +36,7 @@ src
|
|||
│ ├── app-shell.component.spec.ts
|
||||
│ └── app-shell.component.ts
|
||||
└── main.server.ts # main server application bootstrapping
|
||||
</docs-code>
|
||||
```
|
||||
|
||||
<docs-step title="Verify the application is built with the shell content">
|
||||
|
||||
|
|
|
|||
|
|
@ -33,8 +33,7 @@ Services can depend on other services.
|
|||
For example, here's a `HeroService` that depends on the `Logger` service, and also uses `BackendService` to get heroes.
|
||||
That service in turn might depend on the `HttpClient` service to fetch heroes asynchronously from a server:
|
||||
|
||||
<docs-code header="hero.service.ts" language="typescript"
|
||||
highlight="[7,8,12,13]">
|
||||
```ts {header: "hero.service.ts", highlight="[7,8,12,13]"}
|
||||
import { inject } from "@angular/core";
|
||||
|
||||
export class HeroService {
|
||||
|
|
@ -51,7 +50,7 @@ this.logger.log(`Fetched ${this.heroes.length} heroes.`);
|
|||
return this.heroes;
|
||||
}
|
||||
}
|
||||
</docs-code>
|
||||
```
|
||||
|
||||
## Creating an injectable service with the CLI
|
||||
|
||||
|
|
@ -61,9 +60,9 @@ To generate a new `HeroService` class in the `src/app/heroes` folder, follow the
|
|||
|
||||
1. Run this [Angular CLI](/tools/cli) command:
|
||||
|
||||
<docs-code language="sh">
|
||||
```sh
|
||||
ng generate service heroes/hero
|
||||
</docs-code>
|
||||
```
|
||||
|
||||
This command creates the following default `HeroService`:
|
||||
|
||||
|
|
|
|||
|
|
@ -22,7 +22,7 @@ NOTE: Signal Forms are [experimental](reference/releases#experimental) as of Ang
|
|||
The best way to understand the differences is to see the same form implemented in all three approaches.
|
||||
|
||||
<docs-code-multifile>
|
||||
<docs-code header="Signal forms" path="adev/src/content/examples/signal-forms/src/comparison/app/signal-forms.ts"/>
|
||||
<docs-code language="angular-ts" header="Signal forms" path="adev/src/content/examples/signal-forms/src/comparison/app/signal-forms.ts"/>
|
||||
<docs-code header="Reactive forms" path="adev/src/content/examples/signal-forms/src/comparison/app/reactive-forms.ts"/>
|
||||
<docs-code header="Template-driven forms" path="adev/src/content/examples/signal-forms/src/comparison/app/template-driven-forms.ts"/>
|
||||
</docs-code-multifile>
|
||||
|
|
|
|||
|
|
@ -652,7 +652,7 @@ The `validateHttp()` validation rule:
|
|||
|
||||
While async validation runs, the field's `pending()` signal returns `true`. Use this to show loading indicators:
|
||||
|
||||
```ts
|
||||
```angular-html
|
||||
@if (form.username().pending()) {
|
||||
<span class="spinner">Checking...</span>
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,8 +2,6 @@
|
|||
|
||||
The [Angular CLI][CliMain] automatically includes locale data if you run the [`ng build`][CliBuild] command with the `--localize` option.
|
||||
|
||||
<!--todo: replace with docs-code -->
|
||||
|
||||
```shell
|
||||
ng build --localize
|
||||
```
|
||||
|
|
|
|||
|
|
@ -86,19 +86,19 @@ To create a translation file for a locale or language, complete the following ac
|
|||
1. Make a copy of the source language file to create a _translation_ file for each language.
|
||||
1. Rename the _translation_ file to add the locale.
|
||||
|
||||
<docs-code language="file">
|
||||
```file {hideCopy}
|
||||
|
||||
messages.xlf --> messages.{locale}.xlf
|
||||
|
||||
</docs-code>
|
||||
```
|
||||
|
||||
1. Create a new directory at your project root named `locale`.
|
||||
|
||||
<docs-code language="file">
|
||||
```file {hideCopy}
|
||||
|
||||
src/locale
|
||||
|
||||
</docs-code>
|
||||
```
|
||||
|
||||
1. Move the _translation_ file to the new directory.
|
||||
1. Send the _translation_ file to your translator.
|
||||
|
|
@ -145,7 +145,7 @@ The following actions describe the translation process for French.
|
|||
1. Translate the other text nodes.
|
||||
The following example displays the way to translate.
|
||||
|
||||
<docs-code header="src/locale/messages.fr.xlf (<trans-unit>)" path="adev/src/content/examples/i18n/doc-files/messages.fr.xlf" visibleRegion="translated-other-nodes"/>
|
||||
<docs-code header="src/locale/messages.fr.xlf (<trans-unit>)" path="adev/src/content/examples/i18n/doc-files/messages.fr.xlf" visibleRegion="translated-other-nodes"/>
|
||||
|
||||
IMPORTANT: Don't change the IDs for translation units.
|
||||
Each `id` attribute is generated by Angular and depends on the content of the component text and the assigned meaning.
|
||||
|
|
|
|||
|
|
@ -42,7 +42,6 @@ imports: [
|
|||
],
|
||||
```
|
||||
|
||||
</docs-code>
|
||||
</docs-step>
|
||||
<docs-step title="(Optional) Set up a Loader">
|
||||
An image loader is not **required** in order to use NgOptimizedImage, but using one with an image CDN enables powerful performance features, including automatic `srcset`s for your images.
|
||||
|
|
|
|||
|
|
@ -70,15 +70,15 @@ Add the `@tailwindcss/postcss` plugin into your PostCSS configuration.
|
|||
|
||||
Add an `@import` to `./src/styles.css` that imports Tailwind CSS.
|
||||
|
||||
<docs-code language="css" header="src/styles.css">
|
||||
```css {header: "src/styles.css"}
|
||||
@import "tailwindcss";
|
||||
</docs-code>
|
||||
```
|
||||
|
||||
If you're using SCSS, add `@use` to `./src/styles.scss`.
|
||||
|
||||
<docs-code language="scss" header="src/styles.scss">
|
||||
```scss {header: "src/styles.scss"}
|
||||
@use "tailwindcss";
|
||||
</docs-code>
|
||||
```
|
||||
|
||||
### 5. Start using Tailwind in your project
|
||||
|
||||
|
|
|
|||
|
|
@ -39,5 +39,5 @@ For a complete list of Angular packages, see the [API reference](api).
|
|||
| [`@angular/cli`](https://github.com/angular/angular-cli) | Contains the Angular CLI binary for running `ng` commands. |
|
||||
| [`@angular-devkit/build-angular`](https://www.npmjs.com/package/@angular-devkit/build-angular) | Contains default CLI builders for bundling, testing, and serving Angular applications and libraries. |
|
||||
| [`rxjs`](https://www.npmjs.com/package/rxjs) | A library for reactive programming using `Observables`. |
|
||||
| [`zone.js`](https://github.com/angular/zone.js) | Angular relies on `zone.js`` to run Angular's change detection processes when native JavaScript operations raise events. |
|
||||
| [`zone.js`](https://github.com/angular/zone.js) | Angular relies on `zone.js` to run Angular's change detection processes when native JavaScript operations raise events. |
|
||||
| [`typescript`](https://www.npmjs.com/package/typescript) | The TypeScript compiler, language server, and built-in type definitions. |
|
||||
|
|
|
|||
|
|
@ -63,7 +63,7 @@ Add the `[field]` directive to the checkbox input:
|
|||
<docs-step title="Display the form values">
|
||||
Below the form, there's a debug section to show current form values. Display each field value using `.value()`:
|
||||
|
||||
```html
|
||||
```angular-html
|
||||
<p>Email: {{ loginForm.email().value() }}</p>
|
||||
<p>Password: {{ loginForm.password().value() ? '••••••••' : '(empty)' }}</p>
|
||||
<p>Remember me: {{ loginForm.rememberMe().value() ? 'Yes' : 'No' }}</p>
|
||||
|
|
|
|||
|
|
@ -18,7 +18,7 @@ Let's display validation feedback!
|
|||
<docs-step title="Add error display for email field">
|
||||
Below the email input, add conditional error display. This will only show errors when the field is both invalid and touched:
|
||||
|
||||
```html
|
||||
```angular-html
|
||||
<label>
|
||||
Email
|
||||
<input type="email" [field]="loginForm.email" />
|
||||
|
|
@ -38,7 +38,7 @@ The `loginForm.email()` call accesses the field's state signal. The `invalid()`
|
|||
<docs-step title="Add error display for password field">
|
||||
Below the password input, add the same pattern for password errors:
|
||||
|
||||
```html
|
||||
```angular-html
|
||||
<label>
|
||||
Password
|
||||
<input type="password" [field]="loginForm.password" />
|
||||
|
|
|
|||
|
|
@ -42,7 +42,7 @@ Update the status indicator to display the current user status by:
|
|||
1. Binding the signal to the class attribute with `[class]="userStatus()"`
|
||||
2. Displaying the status text by replacing `???` with `{{ userStatus() }}`
|
||||
|
||||
```html
|
||||
```angular-html
|
||||
<!-- Update from: -->
|
||||
<div class="status-indicator offline">
|
||||
<span class="status-dot"></span>
|
||||
|
|
|
|||
|
|
@ -66,31 +66,31 @@ This demonstrates how computed signals can perform calculations and combine mult
|
|||
<docs-step title="Display the computed values in the template">
|
||||
The template already has placeholders showing "Loading...". Replace them with your computed signals:
|
||||
|
||||
1. For notifications, replace `Loading...` with an @if block:
|
||||
1. For notifications, replace `Loading...` with an `@if` block:
|
||||
|
||||
```angular-html
|
||||
@if (notificationsEnabled()) {
|
||||
Enabled
|
||||
} @else {
|
||||
Disabled
|
||||
}
|
||||
```
|
||||
```angular-html
|
||||
@if (notificationsEnabled()) {
|
||||
Enabled
|
||||
} @else {
|
||||
Disabled
|
||||
}
|
||||
```
|
||||
|
||||
2. For the message, replace `Loading...` with:
|
||||
1. For the message, replace `Loading...` with:
|
||||
|
||||
```angular-html
|
||||
{{ statusMessage() }}
|
||||
```
|
||||
```angular-html
|
||||
{{ statusMessage() }}
|
||||
```
|
||||
|
||||
3. For working hours, replace `Loading...` with an @if block:
|
||||
1. For working hours, replace `Loading...` with an `@if` block:
|
||||
|
||||
```angular-html
|
||||
@if (isWithinWorkingHours()) {
|
||||
Yes
|
||||
} @else {
|
||||
No
|
||||
}
|
||||
```
|
||||
```angular-html
|
||||
@if (isWithinWorkingHours()) {
|
||||
Yes
|
||||
} @else {
|
||||
No
|
||||
}
|
||||
```
|
||||
|
||||
Notice how computed signals are called just like regular signals - with parentheses!
|
||||
</docs-step>
|
||||
|
|
|
|||
|
|
@ -76,7 +76,7 @@ The host bindings automatically re-evaluate when the signals change - just like
|
|||
<docs-step title="Use the directive in your template">
|
||||
Update the app template to demonstrate the reactive directive:
|
||||
|
||||
```angular-ts
|
||||
```angular-html
|
||||
template: `
|
||||
<div>
|
||||
<h1>Directive with Signals</h1>
|
||||
|
|
|
|||
Loading…
Reference in a new issue