forked from angular/angular
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #143 from angular/main
Create a new pull request by comparing changes across two branches.
- Loading branch information
Showing
208 changed files
with
5,855 additions
and
2,269 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,46 @@ | ||
Placeholder content | ||
The `@for` block repeatedly renders content of a block for each item in a collection. | ||
|
||
@syntax | ||
|
||
```html | ||
@for (item of items; track item.name) { | ||
<li> {{ item.name }} </li> | ||
} @empty { | ||
<li> There are no items. </li> | ||
} | ||
``` | ||
|
||
@description | ||
|
||
The `@for` block renders its content in response to changes in a collection. Collections can be any JavaScript [iterable](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Iteration_protocols), but there are performance advantages of using a regular `Array`. | ||
|
||
You can optionally include an `@empty` section immediately after the `@for` block content. The content of the `@empty` block displays when there are no items. | ||
|
||
<h3> track and objects identity </h3> | ||
|
||
The value of the `track` expression determines a key used to associate array items with the views in the DOM. Having clear indication of the item identity allows Angular to execute a minimal set of DOM operations as items are added, removed or moved in a collection. | ||
|
||
Loops over immutable data without `trackBy` as one of the most common causes for performance issues across Angular applications. Because of the potential for poor performance, the `track` expression is required for the `@for` loops. When in doubt, using `track $index` is a good default. | ||
|
||
<h3> `$index` and other contextual variables </h3> | ||
|
||
Inside `@for` contents, several implicit variables are always available: | ||
|
||
| Variable | Meaning | | ||
| -------- | ------- | | ||
| `$count` | Number of items in a collection iterated over | | ||
| `$index` | Index of the current row | | ||
| `$first` | Whether the current row is the first row | | ||
| `$last` | Whether the current row is the last row | | ||
| `$even` | Whether the current row index is even | | ||
| `$odd` | Whether the current row index is odd | | ||
|
||
These variables are always available with these names, but can be aliased via a `let` segment: | ||
|
||
```html | ||
@for (item of items; track item.id; let idx = $index, e = $even) { | ||
Item #{{ idx }}: {{ item.name }} | ||
} | ||
``` | ||
|
||
The aliasing is especially useful in case of using nested `@for` blocks where contextual variable names could collide. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,25 @@ | ||
Control flow block used to conditionally render content in the DOM. | ||
The `@if` block conditionally displays its content when its condition expression is truthy. | ||
|
||
@syntax | ||
|
||
```html | ||
@if ( <condition> ) { | ||
<!-- conditional template fragment --> | ||
@if (a > b) { | ||
{{a}} is greater than {{b}} | ||
} @else if (b > a) { | ||
{{a}} is less than {{b}} | ||
} @else { | ||
{{a}} is equal to {{b}} | ||
} | ||
``` | ||
|
||
@description | ||
This is the full description. | ||
|
||
Content is added and removed from the DOM based on the evaluation of conditional expressions in the `@if` and `@else` blocks. | ||
|
||
The built-in `@if` supports referencing of expression results to keep a solution for common coding patterns: | ||
|
||
```html | ||
@if (users$ | async; as users) { | ||
{{ users.length }} | ||
} | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,25 @@ | ||
Placeholder content | ||
The `@switch` block is inspired by the JavaScript `switch` statement: | ||
|
||
@syntax | ||
|
||
```html | ||
@switch (condition) { | ||
@case (caseA) { | ||
Case A. | ||
} | ||
@case (caseB) { | ||
Case B. | ||
} | ||
@default { | ||
Default case. | ||
} | ||
} | ||
``` | ||
|
||
@description | ||
|
||
The `@switch` blocks displays content selected by one of the cases matching against the conditional expression. The value of the conditional expression is compared to the case expression using the `===` operator. | ||
|
||
The `@default` block is optional and can be omitted. If no `@case` matches the expression and there is no `@default` block, nothing is shown. | ||
|
||
**`@switch` does not have fallthrough**, so you do not need an equivalent to a `break` or `return` statement. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,35 +1,26 @@ | ||
// #docplaster | ||
import { importProvidersFrom } from '@angular/core'; | ||
import { provideProtractorTestingSupport } from '@angular/platform-browser'; | ||
import { provideClientHydration} from '@angular/platform-browser'; | ||
import { ApplicationConfig } from '@angular/core'; | ||
import { provideRouter } from '@angular/router'; | ||
import { provideHttpClient, withFetch } from '@angular/common/http'; | ||
import {provideHttpClient, withFetch} from '@angular/common/http'; | ||
import {ApplicationConfig, importProvidersFrom} from '@angular/core'; | ||
import {provideClientHydration, provideProtractorTestingSupport} from '@angular/platform-browser'; | ||
import {provideRouter} from '@angular/router'; | ||
import {HttpClientInMemoryWebApiModule} from 'angular-in-memory-web-api'; | ||
|
||
import { routes } from './app.routes'; | ||
|
||
import { HttpClientInMemoryWebApiModule } from 'angular-in-memory-web-api'; | ||
import { InMemoryDataService } from './in-memory-data.service'; | ||
import {routes} from './app.routes'; | ||
import {InMemoryDataService} from './in-memory-data.service'; | ||
|
||
export const appConfig: ApplicationConfig = { | ||
providers: [ | ||
provideRouter(routes), | ||
// TODO: Enable using Fetch API when disabling `HttpClientInMemoryWebApiModule`. | ||
provideHttpClient(/* withFetch()*/ ), | ||
provideClientHydration(), | ||
provideProtractorTestingSupport(), // essential for e2e testing | ||
// TODO: Enable using Fetch API when disabling `HttpClientInMemoryWebApiModule`. | ||
provideHttpClient(/* withFetch()*/), provideClientHydration(), | ||
provideProtractorTestingSupport(), // essential for e2e testing | ||
|
||
// #docregion in-mem | ||
// TODO: Remove from production apps | ||
importProvidersFrom( | ||
// The HttpClientInMemoryWebApiModule module intercepts HTTP requests | ||
// and returns simulated server responses. | ||
// Remove it when a real server is ready to receive requests. | ||
HttpClientInMemoryWebApiModule.forRoot( | ||
InMemoryDataService, { dataEncapsulation: false } | ||
) | ||
), | ||
// #enddocregion in-mem | ||
// The HttpClientInMemoryWebApiModule module intercepts HTTP requests | ||
// and returns simulated server responses. | ||
// Remove it when a real server is ready to receive requests. | ||
HttpClientInMemoryWebApiModule.forRoot(InMemoryDataService, {dataEncapsulation: false})), | ||
// ... | ||
], | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.