Skip to content

Commit 8f3fdc3

Browse files
SkyZeroZxkirjs
authored andcommitted
docs: update code snippets in reference doocumentation
1 parent c1dfd9c commit 8f3fdc3

File tree

23 files changed

+66
-65
lines changed

23 files changed

+66
-65
lines changed

adev/src/content/reference/errors/NG0300.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ Two or more [components](guide/components) use the same element selector. Becaus
66

77
This error occurs at runtime when you apply two selectors to a single node, each of which matches a different component, or when you apply a single selector to a node and it matches more than one component.
88

9-
```ts
9+
```angular-ts
1010
import {Component} from '@angular/core';
1111
1212
@Component({

adev/src/content/reference/errors/NG0500.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ More information about hydration can be found in [this guide](guide/hydration).
88

99
The following example will trigger the error.
1010

11-
```typescript
11+
```angular-ts
1212
@Component({
1313
selector: 'app-example',
1414
template: '<div><span>world</span></div>',

adev/src/content/reference/errors/NG0503.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ More information about hydration can be found in [this guide](guide/hydration).
66

77
The following examples will trigger the error.
88

9-
```typescript
9+
```angular-ts
1010
@Component({
1111
selector: 'dynamic',
1212
template: `

adev/src/content/reference/errors/NG0504.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ The following examples will trigger the error.
1010

1111
In this example, the `ngSkipHydration` attribute is applied to a `<div>` using host bindings of a directive. Since the `<div>` doesn't act as a component host node, Angular will throw an error.
1212

13-
```typescript
13+
```angular-ts
1414
@Directive({
1515
selector: '[dir]',
1616
host: {ngSkipHydration: 'true'},
@@ -34,7 +34,7 @@ class SimpleComponent {
3434
In this example, the `ngSkipHydration` is applied to a `<div>` as an attribute via a template.
3535
Since the `<div>` doesn't act as a component host node, Angular will throw an error.
3636

37-
```typescript
37+
```angular-ts
3838
@Component({
3939
selector: 'app',
4040
template: `

adev/src/content/reference/errors/NG0955.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
A track expression specified in the `@for` loop evaluated to duplicated keys for a given collection, ex.:
44

5-
```typescript
5+
```angular-ts
66
@Component({
77
template: `@for (item of items; track item.value) {{{item.value}}}`,
88
})
@@ -21,7 +21,7 @@ There is also performance penalty associated with duplicated keys - internally A
2121

2222
Change the tracking expression such that it uniquely identifies an item in a collection. In the discussed example the correct track expression would use the unique `key` property (`item.key`):
2323

24-
```typescript
24+
```angular-ts
2525
@Component({
2626
template: `@for (item of items; track item.key) {{{item.value}}}`,
2727
})

adev/src/content/reference/errors/NG0956.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
The identity track expression specified in the `@for` loop caused re-creation of the DOM corresponding to _all_ items. This is a very expensive operation that commonly occurs when working with immutable data structures. For example:
44

5-
```typescript
5+
```angular-ts
66
@Component({
77
template: `
88
<button (click)="toggleAllDone()">All done!</button>
@@ -33,7 +33,7 @@ Apart from having a high performance penalty, re-creating the DOM tree results i
3333

3434
Change the tracking expression such that it uniquely identifies an item in a collection, regardless of its object identity. In the discussed example, the correct track expression would use the unique `id` property (`item.id`):
3535

36-
```typescript
36+
```angular-ts
3737
@Component({
3838
template: `
3939
<button (click)="toggleAllDone()">All done!</button>

adev/src/content/reference/errors/NG3003.md

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,42 +3,42 @@
33
A component, directive, or pipe that is referenced by this component would require the compiler to add an import that would lead to a cycle of imports.
44
For example, consider a scenario where a `ParentComponent` references a `ChildComponent` in its template:
55

6-
<docs-code header="parent.component.ts" language="angular-ts">
6+
```angular-ts {header:"parent.component.ts"}
77
import {Component} from '@angular/core';
88
import {ChildComponent} from './child.component';
99
1010
@Component({
11-
selector: 'app-parent',
12-
imports: [ChildComponent],
13-
template: '<app-child/>',
11+
selector: 'app-parent',
12+
imports: [ChildComponent],
13+
template: '<app-child/>',
1414
})
1515
export class ParentComponent {}
16-
</docs-code>
16+
```
1717

18-
<docs-code header="child.component.ts" language="angular-ts">
18+
```angular-ts {header:"child.component.ts"}
1919
import {Component, inject} from '@angular/core';
2020
import {ParentComponent} from './parent.component';
2121
2222
@Component({
23-
selector: 'app-child',
24-
template: 'The child!',
23+
selector: 'app-child',
24+
template: 'The child!',
2525
})
2626
export class ChildComponent {
27-
private parent = inject(ParentComponent);
27+
private parent = inject(ParentComponent);
2828
}
29-
</docs-code>
29+
```
3030

3131
There is already an import from `child.component.ts` to `parent.component.ts` since the `ChildComponent` references the `ParentComponent` in its constructor.
3232

3333
HELPFUL: The parent component's template contains `<child></child>`.
3434
The generated code for this template must therefore contain a reference to the `ChildComponent` class.
3535
In order to make this reference, the compiler would have to add an import from `parent.component.ts` to `child.component.ts`, which would cause an import cycle:
3636

37-
<docs-code language="text">
37+
```text
3838
3939
parent.component.ts -> child.component.ts -> parent.component.ts
4040
41-
</docs-code>
41+
```
4242

4343
## Remote Scoping
4444

adev/src/content/reference/extended-diagnostics/NG8101.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
This diagnostic detects a backwards "banana-in-box" syntax for [two-way bindings](guide/templates/two-way-binding).
44

5-
```
5+
```html
66

77
<user-viewer ([user])="loggedInUser" />
88
```
@@ -18,7 +18,7 @@ Fix the typo.
1818
As the name suggests, the banana `(` should go _inside_ the box `[]`.
1919
In this case:
2020

21-
```
21+
```html
2222

2323
<user-viewer [(user)]="loggedInUser" />
2424
```

adev/src/content/reference/extended-diagnostics/NG8102.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ Double-check the type of the input and confirm whether it is actually expected t
3232

3333
If the input should be nullable, add `null` or `undefined` to its type to indicate this.
3434

35-
```ts
35+
```angular-ts
3636
3737
import {Component} from '@angular/core';
3838
@@ -49,7 +49,7 @@ username: string | null = 'Angelino';
4949

5050
If the input should _not_ be nullable, delete the `??` operator and its right operand, since the value is guaranteed by TypeScript to always be non-nullable.
5151

52-
```ts
52+
```angular-ts
5353
5454
import {Component} from '@angular/core';
5555

adev/src/content/reference/extended-diagnostics/NG8105.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
This diagnostic is emitted when an expression used in `*ngFor` is missing the `let` keyword.
44

5-
```typescript
5+
```angular-ts
66
import { Component } from '@angular/core';
77
88
@Component({
@@ -22,7 +22,7 @@ A missing `let` is indicative of a syntax error in the `*ngFor` string. It also
2222

2323
Add the missing `let` keyword.
2424

25-
```typescript
25+
```angular-ts
2626
import { Component } from '@angular/core';
2727
2828
@Component({

0 commit comments

Comments
 (0)