_id
stringlengths
21
254
text
stringlengths
1
93.7k
metadata
dict
angular/adev/src/content/guide/pipes/overview.md_0_1920
# Understanding Pipes Use pipes to transform strings, currency amounts, dates, and other data for display. ## What is a pipe Pipes are simple functions to use in templates to accept an input value and return a transformed value. Pipes are useful because you can use them throughout your application, while only declar...
{ "end_byte": 1920, "start_byte": 0, "url": "https://github.com/angular/angular/blob/main/adev/src/content/guide/pipes/overview.md" }
angular/adev/src/content/guide/pipes/precedence.md_0_898
# Pipe precedence in template expressions Sometimes you want to choose between two values, based on some condition, before passing the choice to the pipe. You could use the JavaScript ternary operator (`?:`) in the template to make that choice. Beware! The pipe operator has a higher precedence than the JavaScript ter...
{ "end_byte": 898, "start_byte": 0, "url": "https://github.com/angular/angular/blob/main/adev/src/content/guide/pipes/precedence.md" }
angular/adev/src/content/guide/pipes/change-detection.md_0_8114
# Change detection with pipes Pipes are often used with data-bound values that might change based on user actions. If the data is a primitive input value, such as `String` or `Number`, or an object reference as input, such as `Date` or `Array`, Angular executes the pipe whenever it detects a change for the value. <do...
{ "end_byte": 8114, "start_byte": 0, "url": "https://github.com/angular/angular/blob/main/adev/src/content/guide/pipes/change-detection.md" }
angular/adev/src/content/guide/pipes/transform-data.md_0_2863
# Custom pipes for new transforms Create custom pipes to encapsulate transformations that are not provided with the built-in pipes. Then, use your custom pipe in template expressions, the same way you use built-in pipes—to transform input values to output values for display. ## Marking a class as a pipe To mark a cl...
{ "end_byte": 2863, "start_byte": 0, "url": "https://github.com/angular/angular/blob/main/adev/src/content/guide/pipes/transform-data.md" }
angular/adev/src/content/guide/pipes/BUILD.bazel_0_776
load("//adev/shared-docs:index.bzl", "generate_guides") generate_guides( name = "pipes", srcs = glob([ "*.md", ]), data = [ "//adev/src/content/examples/pipes:src/app/exponential-strength.pipe.ts", "//adev/src/content/examples/pipes:src/app/flying-heroes.component.html", ...
{ "end_byte": 776, "start_byte": 0, "url": "https://github.com/angular/angular/blob/main/adev/src/content/guide/pipes/BUILD.bazel" }
angular/adev/src/content/guide/pipes/unwrapping-data-observables.md_0_1307
# Unwrapping data from an observable Observables let you pass messages between parts of your application. You can use observables for event handling, asynchronous programming, and handling multiple values. Observables can deliver single or multiple values of any type, either synchronously (as a function delivers a val...
{ "end_byte": 1307, "start_byte": 0, "url": "https://github.com/angular/angular/blob/main/adev/src/content/guide/pipes/unwrapping-data-observables.md" }
angular/adev/src/content/guide/testing/attribute-directives.md_0_3624
# Testing Attribute Directives An *attribute directive* modifies the behavior of an element, component or another directive. Its name reflects the way the directive is applied: as an attribute on a host element. ## Testing the `HighlightDirective` The sample application's `HighlightDirective` sets the background co...
{ "end_byte": 3624, "start_byte": 0, "url": "https://github.com/angular/angular/blob/main/adev/src/content/guide/testing/attribute-directives.md" }
angular/adev/src/content/guide/testing/overview.md_0_6033
# Testing Testing your Angular application helps you check that your application is working as you expect. ## Set up testing The Angular CLI downloads and installs everything you need to test an Angular application with [Jasmine testing framework](https://jasmine.github.io). The project you create with the CLI is i...
{ "end_byte": 6033, "start_byte": 0, "url": "https://github.com/angular/angular/blob/main/adev/src/content/guide/testing/overview.md" }
angular/adev/src/content/guide/testing/pipes.md_0_1383
# Testing Pipes You can test [pipes](guide/templates/pipes) without the Angular testing utilities. ## Testing the `TitleCasePipe` A pipe class has one method, `transform`, that manipulates the input value into a transformed output value. The `transform` implementation rarely interacts with the DOM. Most pipes have n...
{ "end_byte": 1383, "start_byte": 0, "url": "https://github.com/angular/angular/blob/main/adev/src/content/guide/testing/pipes.md" }
angular/adev/src/content/guide/testing/components-basics.md_0_9094
# Basics of testing components A component, unlike all other parts of an Angular application, combines an HTML template and a TypeScript class. The component truly is the template and the class *working together*. To adequately test a component, you should test that they work together as intended. Such tests require ...
{ "end_byte": 9094, "start_byte": 0, "url": "https://github.com/angular/angular/blob/main/adev/src/content/guide/testing/components-basics.md" }
angular/adev/src/content/guide/testing/components-basics.md_9094_10895
### `By.css()` Although the tests in this guide all run in the browser, some applications might run on a different platform at least some of the time. For example, the component might render first on the server as part of a strategy to make the application launch faster on poorly connected devices. The server-side re...
{ "end_byte": 10895, "start_byte": 9094, "url": "https://github.com/angular/angular/blob/main/adev/src/content/guide/testing/components-basics.md" }
angular/adev/src/content/guide/testing/services.md_0_7685
# Testing services To check that your services are working as you intend, you can write tests specifically for them. Services are often the smoothest files to unit test. Here are some synchronous and asynchronous unit tests of the `ValueService` written without assistance from Angular testing utilities. <docs-code h...
{ "end_byte": 7685, "start_byte": 0, "url": "https://github.com/angular/angular/blob/main/adev/src/content/guide/testing/services.md" }
angular/adev/src/content/guide/testing/BUILD.bazel_0_3451
load("//adev/shared-docs:index.bzl", "generate_guides") generate_guides( name = "testing", srcs = glob([ "*.md", ]), data = [ "//adev/src/content/examples/testing:src/app/about/about.component.spec.ts", "//adev/src/content/examples/testing:src/app/about/about.component.ts", ...
{ "end_byte": 3451, "start_byte": 0, "url": "https://github.com/angular/angular/blob/main/adev/src/content/guide/testing/BUILD.bazel" }
angular/adev/src/content/guide/testing/utility-apis.md_0_14225
# Testing Utility APIs This page describes the most useful Angular testing features. The Angular testing utilities include the `TestBed`, the `ComponentFixture`, and a handful of functions that control the test environment. The [`TestBed`](#testbed-api-summary) and [`ComponentFixture`](#component-fixture-api-summary)...
{ "end_byte": 14225, "start_byte": 0, "url": "https://github.com/angular/angular/blob/main/adev/src/content/guide/testing/utility-apis.md" }
angular/adev/src/content/guide/testing/utility-apis.md_14225_27047
## The `ComponentFixture` The `TestBed.createComponent<T>` creates an instance of the component `T` and returns a strongly typed `ComponentFixture` for that component. The `ComponentFixture` properties and methods provide access to the component, its DOM representation, and aspects of its Angular environment. ### `C...
{ "end_byte": 27047, "start_byte": 14225, "url": "https://github.com/angular/angular/blob/main/adev/src/content/guide/testing/utility-apis.md" }
angular/adev/src/content/guide/testing/code-coverage.md_0_2050
# Find out how much code you're testing The Angular CLI can run unit tests and create code coverage reports. Code coverage reports show you any parts of your code base that might not be properly tested by your unit tests. To generate a coverage report run the following command in the root of your project. <docs-cod...
{ "end_byte": 2050, "start_byte": 0, "url": "https://github.com/angular/angular/blob/main/adev/src/content/guide/testing/code-coverage.md" }
angular/adev/src/content/guide/testing/debugging.md_0_822
# Debugging tests If your tests aren't working as you expect them to, you can inspect and debug them in the browser. Debug specs in the browser in the same way that you debug an application. 1. Reveal the Karma browser window. See [Set up testing](guide/testing#set-up-testing) if you need help with this step. 1...
{ "end_byte": 822, "start_byte": 0, "url": "https://github.com/angular/angular/blob/main/adev/src/content/guide/testing/debugging.md" }
angular/adev/src/content/guide/testing/components-scenarios.md_0_7030
# Component testing scenarios This guide explores common component testing use cases. ## Component binding In the example application, the `BannerComponent` presents static title text in the HTML template. After a few changes, the `BannerComponent` presents a dynamic title by binding to the component's `title` prop...
{ "end_byte": 7030, "start_byte": 0, "url": "https://github.com/angular/angular/blob/main/adev/src/content/guide/testing/components-scenarios.md" }
angular/adev/src/content/guide/testing/components-scenarios.md_7030_10529
## Component with a dependency Components often have service dependencies. The `WelcomeComponent` displays a welcome message to the logged-in user. It knows who the user is based on a property of the injected `UserService`: <docs-code header="app/welcome/welcome.component.ts" path="adev/src/content/examples/testing/...
{ "end_byte": 10529, "start_byte": 7030, "url": "https://github.com/angular/angular/blob/main/adev/src/content/guide/testing/components-scenarios.md" }
angular/adev/src/content/guide/testing/components-scenarios.md_10529_19042
## Component with async service In this sample, the `AboutComponent` template hosts a `TwainComponent`. The `TwainComponent` displays Mark Twain quotes. <docs-code header="app/twain/twain.component.ts (template)" path="adev/src/content/examples/testing/src/app/twain/twain.component.ts" visibleRegion="template" /> HE...
{ "end_byte": 19042, "start_byte": 10529, "url": "https://github.com/angular/angular/blob/main/adev/src/content/guide/testing/components-scenarios.md" }
angular/adev/src/content/guide/testing/components-scenarios.md_19042_28043
### Async observables You might be satisfied with the test coverage of these tests. However, you might be troubled by the fact that the real service doesn't quite behave this way. The real service sends requests to a remote server. A server takes time to respond and the response certainly won't be available immediate...
{ "end_byte": 28043, "start_byte": 19042, "url": "https://github.com/angular/angular/blob/main/adev/src/content/guide/testing/components-scenarios.md" }
angular/adev/src/content/guide/testing/components-scenarios.md_28043_33800
## Component inside a test host The previous tests played the role of the host `DashboardComponent` themselves. But does the `DashboardHeroComponent` work correctly when properly data-bound to a host component? <docs-code header="app/dashboard/dashboard-hero.component.spec.ts (test host)" path="adev/src/content/examp...
{ "end_byte": 33800, "start_byte": 28043, "url": "https://github.com/angular/angular/blob/main/adev/src/content/guide/testing/components-scenarios.md" }
angular/adev/src/content/guide/testing/components-scenarios.md_33800_41003
## Nested component tests Component templates often have nested components, whose templates might contain more components. The component tree can be very deep and sometimes the nested components play no role in testing the component at the top of the tree. The `AppComponent`, for example, displays a navigation bar w...
{ "end_byte": 41003, "start_byte": 33800, "url": "https://github.com/angular/angular/blob/main/adev/src/content/guide/testing/components-scenarios.md" }
angular/adev/src/content/guide/testing/components-scenarios.md_41003_49344
Calling `compileComponents()` HELPFUL: Ignore this section if you *only* run tests with the CLI `ng test` command because the CLI compiles the application before running the tests. If you run tests in a **non-CLI environment**, the tests might fail with a message like this one: <docs-code hideCopy language="shell">...
{ "end_byte": 49344, "start_byte": 41003, "url": "https://github.com/angular/angular/blob/main/adev/src/content/guide/testing/components-scenarios.md" }
angular/adev/src/content/guide/testing/components-scenarios.md_49344_54092
Override component providers The `HeroDetailComponent` provides its own `HeroDetailService`. <docs-code header="app/hero/hero-detail.component.ts (prototype)" path="adev/src/content/examples/testing/src/app/hero/hero-detail.component.ts" visibleRegion="prototype"/> It's not possible to stub the component's `HeroDet...
{ "end_byte": 54092, "start_byte": 49344, "url": "https://github.com/angular/angular/blob/main/adev/src/content/guide/testing/components-scenarios.md" }
angular/adev/src/content/guide/components/lifecycle.md_0_8541
# Component Lifecycle Tip: This guide assumes you've already read the [Essentials Guide](essentials). Read that first if you're new to Angular. A component's **lifecycle** is the sequence of steps that happen between the component's creation and its destruction. Each step represents a different part of Angular's proc...
{ "end_byte": 8541, "start_byte": 0, "url": "https://github.com/angular/angular/blob/main/adev/src/content/guide/components/lifecycle.md" }
angular/adev/src/content/guide/components/lifecycle.md_8541_13769
### afterRender and afterNextRender The `afterRender` and `afterNextRender` functions let you register a **render callback** to be invoked after Angular has finished rendering _all components_ on the page into the DOM. These functions are different from the other lifecycle hooks described in this guide. Rather than a...
{ "end_byte": 13769, "start_byte": 8541, "url": "https://github.com/angular/angular/blob/main/adev/src/content/guide/components/lifecycle.md" }
angular/adev/src/content/guide/components/queries.md_0_6598
# Referencing component children with queries Tip: This guide assumes you've already read the [Essentials Guide](essentials). Read that first if you're new to Angular. A component can define **queries** that find child elements and read values from their injectors. Developers most commonly use queries to retrieve re...
{ "end_byte": 6598, "start_byte": 0, "url": "https://github.com/angular/angular/blob/main/adev/src/content/guide/components/queries.md" }
angular/adev/src/content/guide/components/queries.md_6598_10285
uery options All query decorators accept an options object as a second parameter. These options control how the query finds its results. ### Static queries `@ViewChild` and `@ContentChild` queries accept the `static` option. ```angular-ts @Component({ selector: 'custom-card', template: '<custom-card-header>Visi...
{ "end_byte": 10285, "start_byte": 6598, "url": "https://github.com/angular/angular/blob/main/adev/src/content/guide/components/queries.md" }
angular/adev/src/content/guide/components/inputs.md_0_6829
# Accepting data with input properties Tip: This guide assumes you've already read the [Essentials Guide](essentials). Read that first if you're new to Angular. Tip: If you're familiar with other web frameworks, input properties are similar to _props_. When creating a component, you can mark specific class propertie...
{ "end_byte": 6829, "start_byte": 0, "url": "https://github.com/angular/angular/blob/main/adev/src/content/guide/components/inputs.md" }
angular/adev/src/content/guide/components/inheritance.md_0_2640
# Inheritance Tip: This guide assumes you've already read the [Essentials Guide](essentials). Read that first if you're new to Angular. Angular components are TypeScript classes and participate in standard JavaScript inheritance semantics. A component can extend any base class: ```ts export class ListboxBase { va...
{ "end_byte": 2640, "start_byte": 0, "url": "https://github.com/angular/angular/blob/main/adev/src/content/guide/components/inheritance.md" }
angular/adev/src/content/guide/components/outputs.md_0_3564
# Custom events with outputs Tip: This guide assumes you've already read the [Essentials Guide](essentials). Read that first if you're new to Angular. Angular components can define custom events by assigning a property to a new `EventEmitter` and adding the `@Output` decorator: <docs-code language="ts" highlight="">...
{ "end_byte": 3564, "start_byte": 0, "url": "https://github.com/angular/angular/blob/main/adev/src/content/guide/components/outputs.md" }
angular/adev/src/content/guide/components/advanced-configuration.md_0_2088
# Advanced component configuration Tip: This guide assumes you've already read the [Essentials Guide](essentials). Read that first if you're new to Angular. ## ChangeDetectionStrategy The `@Component` decorator accepts a `changeDetection` option that controls the component's **change detection mode**. There are two ...
{ "end_byte": 2088, "start_byte": 0, "url": "https://github.com/angular/angular/blob/main/adev/src/content/guide/components/advanced-configuration.md" }
angular/adev/src/content/guide/components/output-function.md_0_3725
# Function-based outputs The `output()` function declares an output in a directive or component. Outputs allow you to emit values to parent components. <docs-code language="ts" highlight="[[5], [8]]"> import {Component, output} from '@angular/core'; @Component({...}) export class MyComp { nameChange = output<strin...
{ "end_byte": 3725, "start_byte": 0, "url": "https://github.com/angular/angular/blob/main/adev/src/content/guide/components/output-function.md" }
angular/adev/src/content/guide/components/content-projection.md_0_6316
# Content projection with ng-content Tip: This guide assumes you've already read the [Essentials Guide](essentials). Read that first if you're new to Angular. You often need to create components that act as containers for different types of content. For example, you may want to create a custom card component: ```ang...
{ "end_byte": 6316, "start_byte": 0, "url": "https://github.com/angular/angular/blob/main/adev/src/content/guide/components/content-projection.md" }
angular/adev/src/content/guide/components/anatomy-of-components.md_0_4131
<docs-decorative-header title="Anatomy of a component" imgSrc="adev/src/assets/images/components.svg"> <!-- markdownlint-disable-line --> </docs-decorative-header> Tip: This guide assumes you've already read the [Essentials Guide](essentials). Read that first if you're new to Angular. Every component must have: * A ...
{ "end_byte": 4131, "start_byte": 0, "url": "https://github.com/angular/angular/blob/main/adev/src/content/guide/components/anatomy-of-components.md" }
angular/adev/src/content/guide/components/importing.md_0_1165
# Importing and using components Tip: This guide assumes you've already read the [Essentials Guide](essentials). Read that first if you're new to Angular. Angular supports two ways of making a component available to other components: as a standalone component or in an `NgModule`. ## Standalone components A **standa...
{ "end_byte": 1165, "start_byte": 0, "url": "https://github.com/angular/angular/blob/main/adev/src/content/guide/components/importing.md" }
angular/adev/src/content/guide/components/BUILD.bazel_0_286
load("//adev/shared-docs:index.bzl", "generate_guides") generate_guides( name = "components", srcs = glob([ "*.md", ]), data = [ "//adev/src/assets/images:components.svg", ], mermaid_blocks = True, visibility = ["//adev:__subpackages__"], )
{ "end_byte": 286, "start_byte": 0, "url": "https://github.com/angular/angular/blob/main/adev/src/content/guide/components/BUILD.bazel" }
angular/adev/src/content/guide/components/host-elements.md_0_3334
# Component host elements Tip: This guide assumes you've already read the [Essentials Guide](essentials). Read that first if you're new to Angular. Angular creates an instance of a component for every HTML element that matches the component's selector. The DOM element that matches a component's selector is that compo...
{ "end_byte": 3334, "start_byte": 0, "url": "https://github.com/angular/angular/blob/main/adev/src/content/guide/components/host-elements.md" }
angular/adev/src/content/guide/components/selectors.md_0_6247
# Component selectors Tip: This guide assumes you've already read the [Essentials Guide](essentials). Read that first if you're new to Angular. Every component defines a [CSS selector](https://developer.mozilla.org/docs/Web/CSS/CSS_selectors) that determines how the component is used: <docs-code language="angular-ts...
{ "end_byte": 6247, "start_byte": 0, "url": "https://github.com/angular/angular/blob/main/adev/src/content/guide/components/selectors.md" }
angular/adev/src/content/guide/components/styling.md_0_5133
# Styling components Tip: This guide assumes you've already read the [Essentials Guide](essentials). Read that first if you're new to Angular. Components can optionally include CSS styles that apply to that component's DOM: <docs-code language="angular-ts" highlight="[4]"> @Component({ selector: 'profile-photo', ...
{ "end_byte": 5133, "start_byte": 0, "url": "https://github.com/angular/angular/blob/main/adev/src/content/guide/components/styling.md" }
angular/adev/src/content/guide/components/dom-apis.md_0_3683
# Using DOM APIs Tip: This guide assumes you've already read the [Essentials Guide](essentials). Read that first if you're new to Angular. Angular handles most DOM creation, updates, and removals for you. However, you might rarely need to directly interact with a component's DOM. Components can inject ElementRef to g...
{ "end_byte": 3683, "start_byte": 0, "url": "https://github.com/angular/angular/blob/main/adev/src/content/guide/components/dom-apis.md" }
angular/adev/src/content/guide/components/programmatic-rendering.md_0_3614
# Programmatically rendering components Tip: This guide assumes you've already read the [Essentials Guide](essentials). Read that first if you're new to Angular. In addition to using a component directly in a template, you can also dynamically render components. There are two main ways to dynamically render a compone...
{ "end_byte": 3614, "start_byte": 0, "url": "https://github.com/angular/angular/blob/main/adev/src/content/guide/components/programmatic-rendering.md" }
angular/adev/src/content/guide/http/overview.md_0_917
# Understanding communicating with backend services using HTTP Most front-end applications need to communicate with a server over the HTTP protocol, to download or upload data and access other back-end services. Angular provides a client HTTP API for Angular applications, the `HttpClient` service class in `@angular/co...
{ "end_byte": 917, "start_byte": 0, "url": "https://github.com/angular/angular/blob/main/adev/src/content/guide/http/overview.md" }
angular/adev/src/content/guide/http/setup.md_0_5357
# Setting up `HttpClient` Before you can use `HttpClient` in your app, you must configure it using [dependency injection](guide/di). ## Providing `HttpClient` through dependency injection `HttpClient` is provided using the `provideHttpClient` helper function, which most apps include in the application `providers` in...
{ "end_byte": 5357, "start_byte": 0, "url": "https://github.com/angular/angular/blob/main/adev/src/content/guide/http/setup.md" }
angular/adev/src/content/guide/http/making-requests.md_0_7458
# Making HTTP requests `HttpClient` has methods corresponding to the different HTTP verbs used to make requests, both to load data and to apply mutations on the server. Each method returns an [RxJS `Observable`](https://rxjs.dev/guide/observable) which, when subscribed, sends the request and then emits the results whe...
{ "end_byte": 7458, "start_byte": 0, "url": "https://github.com/angular/angular/blob/main/adev/src/content/guide/http/making-requests.md" }
angular/adev/src/content/guide/http/making-requests.md_7458_14111
## Receiving raw progress events In addition to the response body or response object, `HttpClient` can also return a stream of raw _events_ corresponding to specific moments in the request lifecycle. These events include when the request is sent, when the response header is returned, and when the body is complete. The...
{ "end_byte": 14111, "start_byte": 7458, "url": "https://github.com/angular/angular/blob/main/adev/src/content/guide/http/making-requests.md" }
angular/adev/src/content/guide/http/testing.md_0_5909
# Test requests As for any external dependency, you must mock the HTTP backend so your tests can simulate interaction with a remote server. The `@angular/common/http/testing` library provides tools to capture requests made by the application, make assertions about them, and mock the responses to emulate your backend's...
{ "end_byte": 5909, "start_byte": 0, "url": "https://github.com/angular/angular/blob/main/adev/src/content/guide/http/testing.md" }
angular/adev/src/content/guide/http/BUILD.bazel_0_182
load("//adev/shared-docs:index.bzl", "generate_guides") generate_guides( name = "http", srcs = glob([ "*.md", ]), visibility = ["//adev:__subpackages__"], )
{ "end_byte": 182, "start_byte": 0, "url": "https://github.com/angular/angular/blob/main/adev/src/content/guide/http/BUILD.bazel" }
angular/adev/src/content/guide/http/interceptors.md_0_9590
# Interceptors `HttpClient` supports a form of middleware known as _interceptors_. TLDR: Interceptors are middleware that allows common patterns around retrying, caching, logging, and authentication to be abstracted away from individual requests. `HttpClient` supports two kinds of interceptors: functional and DI-bas...
{ "end_byte": 9590, "start_byte": 0, "url": "https://github.com/angular/angular/blob/main/adev/src/content/guide/http/interceptors.md" }
angular/adev/src/content/guide/http/security.md_0_4210
# `HttpClient` security `HttpClient` includes built-in support for two common HTTP security mechanisms: XSSI protection and XSRF/CSRF protection. Tip: Also consider adopting a [Content Security Policy](https://developer.mozilla.org/docs/Web/HTTP/Headers/Content-Security-Policy) for your APIs. ## XSSI protection Cro...
{ "end_byte": 4210, "start_byte": 0, "url": "https://github.com/angular/angular/blob/main/adev/src/content/guide/http/security.md" }
angular/adev/src/content/guide/templates/defer.md_0_5220
# Deferred loading with `@defer` Deferrable views, also known as `@defer` blocks, reduce the initial bundle size of your application by deferring the loading of code that is not strictly necessary for the initial rendering of a page. This often results in a faster initial load and improvement in Core Web Vitals (CWV),...
{ "end_byte": 5220, "start_byte": 0, "url": "https://github.com/angular/angular/blob/main/adev/src/content/guide/templates/defer.md" }
angular/adev/src/content/guide/templates/defer.md_5220_14329
Controlling deferred content loading with triggers You can specify **triggers** that control when Angular loads and displays deferred content. When a `@defer` block is triggered, it replaces placeholder content with lazily loaded content. Multiple event triggers can be defined by separating them with a semicolon, `...
{ "end_byte": 14329, "start_byte": 5220, "url": "https://github.com/angular/angular/blob/main/adev/src/content/guide/templates/defer.md" }
angular/adev/src/content/guide/templates/event-listeners.md_0_3536
# Adding event listeners Angular supports defining event listeners on an element in your template by specifying the event name inside parentheses along with a statement that runs every time the event occurs. ## Listening to native events When you want to add event listeners to an HTML element, you wrap the event wit...
{ "end_byte": 3536, "start_byte": 0, "url": "https://github.com/angular/angular/blob/main/adev/src/content/guide/templates/event-listeners.md" }
angular/adev/src/content/guide/templates/overview.md_0_4985
<docs-decorative-header title="Template syntax" imgSrc="adev/src/assets/images/templates.svg"> <!-- markdownlint-disable-line --> In Angular, a template is a chunk of HTML. Use special syntax within a template to leverage many of Angular's features. </docs-decorative-header> Tip: Check out Angular's [Essentials](essen...
{ "end_byte": 4985, "start_byte": 0, "url": "https://github.com/angular/angular/blob/main/adev/src/content/guide/templates/overview.md" }
angular/adev/src/content/guide/templates/pipes.md_0_7960
# Pipes ## Overview Pipes are a special operator in Angular template expressions that allows you to transform data declaratively in your template. Pipes let you declare a transformation function once and then use that transformation across multiple templates. Angular pipes use the vertical bar character (`|`), inspir...
{ "end_byte": 7960, "start_byte": 0, "url": "https://github.com/angular/angular/blob/main/adev/src/content/guide/templates/pipes.md" }
angular/adev/src/content/guide/templates/pipes.md_7960_11963
reating custom pipes You can define a custom pipe by implementing a TypeScript class with the `@Pipe` decorator. A pipe must have two things: - A name, specified in the pipe decorator - A method named `transform` that performs the value transformation. The TypeScript class should additionally implement the `PipeTran...
{ "end_byte": 11963, "start_byte": 7960, "url": "https://github.com/angular/angular/blob/main/adev/src/content/guide/templates/pipes.md" }
angular/adev/src/content/guide/templates/two-way-binding.md_0_4564
# Two-way binding **Two way binding** is a shorthand to simultaneously bind a value into an element, while also giving that element the ability to propagate changes back through this binding. ## Syntax The syntax for two-way binding is a combination of square brackets and parentheses, `[()]`. It combines the syntax ...
{ "end_byte": 4564, "start_byte": 0, "url": "https://github.com/angular/angular/blob/main/adev/src/content/guide/templates/two-way-binding.md" }
angular/adev/src/content/guide/templates/whitespace.md_0_2611
# Whitespace in templates By default, Angular templates do not preserve whitespace that the framework considers unnecessary. This commonly occurs in two situations: whitespace between elements, and collapsible whitespace inside of text. ## Whitespace between elements Most developers prefer to format their templates ...
{ "end_byte": 2611, "start_byte": 0, "url": "https://github.com/angular/angular/blob/main/adev/src/content/guide/templates/whitespace.md" }
angular/adev/src/content/guide/templates/binding.md_0_9521
# Binding dynamic text, properties and attributes In Angular, a **binding** creates a dynamic connection between a component's template and its data. This connection ensures that changes to the component's data automatically update the rendered template. ## Render dynamic text with text interpolation You can bind dy...
{ "end_byte": 9521, "start_byte": 0, "url": "https://github.com/angular/angular/blob/main/adev/src/content/guide/templates/binding.md" }
angular/adev/src/content/guide/templates/ng-content.md_0_1073
# Render templates from a parent component with `ng-content` `<ng-content>` is a special element that accepts markup or a template fragment and controls how components render content. It does not render a real DOM element. Here is an example of a `BaseButton` component that accepts any markup from its parent. ```ang...
{ "end_byte": 1073, "start_byte": 0, "url": "https://github.com/angular/angular/blob/main/adev/src/content/guide/templates/ng-content.md" }
angular/adev/src/content/guide/templates/ng-container.md_0_3768
# Grouping elements with ng-container `<ng-container>` is a special element in Angular that groups multiple elements together or marks a location in a template without rendering a real element in the DOM. ```angular-html <!-- Component template --> <section> <ng-container> <h3>User bio</h3> <p>Here's some i...
{ "end_byte": 3768, "start_byte": 0, "url": "https://github.com/angular/angular/blob/main/adev/src/content/guide/templates/ng-container.md" }
angular/adev/src/content/guide/templates/ng-template.md_0_8304
# Create template fragments with ng-template Inspired by the [native `<template>` element](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/template), the `<ng-template>` element lets you declare a **template fragment** – a section of content that you can dynamically or programmatically render. ## Creating a...
{ "end_byte": 8304, "start_byte": 0, "url": "https://github.com/angular/angular/blob/main/adev/src/content/guide/templates/ng-template.md" }
angular/adev/src/content/guide/templates/ng-template.md_8304_9587
Structural directives A **structural directive** is any directive that: - Injects `TemplateRef` - Injects `ViewContainerRef` and programmatically renders the injected `TemplateRef` Angular supports a special convenience syntax for structural directives. If you apply the directive to an element and prefix the direct...
{ "end_byte": 9587, "start_byte": 8304, "url": "https://github.com/angular/angular/blob/main/adev/src/content/guide/templates/ng-template.md" }
angular/adev/src/content/guide/templates/control-flow.md_0_5071
# Control flow Angular templates support control flow blocks that let you conditionally show, hide, and repeat elements. Note: This was previously accomplished with the *ngIf, *ngFor, and \*ngSwitch directives. ## Conditionally display content with `@if`, `@else-if` and `@else` The `@if` block conditionally display...
{ "end_byte": 5071, "start_byte": 0, "url": "https://github.com/angular/angular/blob/main/adev/src/content/guide/templates/control-flow.md" }
angular/adev/src/content/guide/templates/BUILD.bazel_0_257
load("//adev/shared-docs:index.bzl", "generate_guides") generate_guides( name = "templates", srcs = glob([ "*.md", ]), data = [ "//adev/src/assets/images:templates.svg", ], visibility = ["//adev:__subpackages__"], )
{ "end_byte": 257, "start_byte": 0, "url": "https://github.com/angular/angular/blob/main/adev/src/content/guide/templates/BUILD.bazel" }
angular/adev/src/content/guide/templates/expression-syntax.md_0_5599
# Expression Syntax Angular expressions are based on JavaScript, but differ in some key ways. This guide walks through the similarities and differences between Angular expressions and standard JavaScript. ## Value literals Angular supports a subset of [literal values](https://developer.mozilla.org/en-US/docs/Glossar...
{ "end_byte": 5599, "start_byte": 0, "url": "https://github.com/angular/angular/blob/main/adev/src/content/guide/templates/expression-syntax.md" }
angular/adev/src/content/guide/templates/variables.md_0_7027
# Variables in templates Angular has two types of variable declarations in templates: local template variables and template reference variables. ## Local template variables with `@let` Angular's `@let` syntax allows you to define a local variable and re-use it across a template, similar to the [JavaScript `let` synt...
{ "end_byte": 7027, "start_byte": 0, "url": "https://github.com/angular/angular/blob/main/adev/src/content/guide/templates/variables.md" }
angular/adev/src/content/guide/routing/overview.md_0_1490
<docs-decorative-header title="Angular Routing" imgSrc="adev/src/assets/images/routing.svg"> <!-- markdownlint-disable-line --> Routing helps you change what the user sees in a single-page app. </docs-decorative-header> In a single-page app, you change what the user sees by showing or hiding portions of the display th...
{ "end_byte": 1490, "start_byte": 0, "url": "https://github.com/angular/angular/blob/main/adev/src/content/guide/routing/overview.md" }
angular/adev/src/content/guide/routing/routing-with-urlmatcher.md_0_5053
# Creating custom route matches The Angular Router supports a powerful matching strategy that you can use to help users navigate your application. This matching strategy supports static routes, variable routes with parameters, wildcard routes, and so on. Also, build your own custom pattern matching for situations in w...
{ "end_byte": 5053, "start_byte": 0, "url": "https://github.com/angular/angular/blob/main/adev/src/content/guide/routing/routing-with-urlmatcher.md" }
angular/adev/src/content/guide/routing/common-router-tasks.md_0_8144
# Common Routing Tasks This topic describes how to implement many of the common tasks associated with adding the Angular router to your application. ## Generate an application with routing enabled The following command uses the Angular CLI to generate a basic Angular application with application routes. The applicat...
{ "end_byte": 8144, "start_byte": 0, "url": "https://github.com/angular/angular/blob/main/adev/src/content/guide/routing/common-router-tasks.md" }
angular/adev/src/content/guide/routing/common-router-tasks.md_8144_16645
## Setting up redirects To set up a redirect, configure a route with the `path` you want to redirect from, the `component` you want to redirect to, and a `pathMatch` value that tells the router how to match the URL. ```ts const routes: Routes = [ { path: 'first-component', component: FirstComponent }, { path: 'se...
{ "end_byte": 16645, "start_byte": 8144, "url": "https://github.com/angular/angular/blob/main/adev/src/content/guide/routing/common-router-tasks.md" }
angular/adev/src/content/guide/routing/common-router-tasks.md_16645_24193
## Lazy loading You can configure your routes to lazy load modules, which means that Angular only loads modules as needed, rather than loading all modules when the application launches. Additionally, preload parts of your application in the background to improve the user experience. Any route can lazily load its rout...
{ "end_byte": 24193, "start_byte": 16645, "url": "https://github.com/angular/angular/blob/main/adev/src/content/guide/routing/common-router-tasks.md" }
angular/adev/src/content/guide/routing/common-router-tasks.md_24193_28286
## `<base href>` The router uses the browser's [history.pushState](https://developer.mozilla.org/docs/Web/API/History_API/Working_with_the_History_API#adding_and_modifying_history_entries 'HTML5 browser history push-state') for navigation. `pushState` lets you customize in-application URL paths; for example, `localhos...
{ "end_byte": 28286, "start_byte": 24193, "url": "https://github.com/angular/angular/blob/main/adev/src/content/guide/routing/common-router-tasks.md" }
angular/adev/src/content/guide/routing/router-reference.md_0_9740
# Router reference The following sections highlight some core router concepts. ## Router imports The Angular Router is an optional service that presents a particular component view for a given URL. It isn't part of the Angular core and thus is in its own library package, `@angular/router`. Import what you need from...
{ "end_byte": 9740, "start_byte": 0, "url": "https://github.com/angular/angular/blob/main/adev/src/content/guide/routing/router-reference.md" }
angular/adev/src/content/guide/routing/router-reference.md_9740_16871
Router events During each navigation, the `Router` emits navigation events through the `Router.events` property. These events are shown in the following table. | Router event | Details | |:--- |:--- | | [`Navigatio...
{ "end_byte": 16871, "start_byte": 9740, "url": "https://github.com/angular/angular/blob/main/adev/src/content/guide/routing/router-reference.md" }
angular/adev/src/content/guide/routing/BUILD.bazel_0_1141
load("//adev/shared-docs:index.bzl", "generate_guides") generate_guides( name = "routing", srcs = glob([ "*.md", ]), data = [ "//adev/src/assets/images:routing.svg", "//adev/src/content/examples/router:src/app/app.component.1.html", "//adev/src/content/examples/router:sr...
{ "end_byte": 1141, "start_byte": 0, "url": "https://github.com/angular/angular/blob/main/adev/src/content/guide/routing/BUILD.bazel" }
angular/adev/src/content/guide/routing/router-tutorial.md_0_7994
# Using Angular routes in a single-page application This tutorial describes how to build a single-page application, SPA that uses multiple Angular routes. In a Single Page Application \(SPA\), all of your application's functions exist in a single HTML page. As users access your application's features, the browser nee...
{ "end_byte": 7994, "start_byte": 0, "url": "https://github.com/angular/angular/blob/main/adev/src/content/guide/routing/router-tutorial.md" }
angular/adev/src/content/guide/routing/router-tutorial.md_7994_12713
## Identify the active route While users can navigate your application using the links you added in the previous section, they don't have a straightforward way to identify what the active route is. Add this functionality using Angular's `routerLinkActive` directive. 1. From your code editor, open the `app.component.h...
{ "end_byte": 12713, "start_byte": 7994, "url": "https://github.com/angular/angular/blob/main/adev/src/content/guide/routing/router-tutorial.md" }
angular/adev/src/content/guide/performance/overview.md_0_1909
<docs-decorative-header title="Performance" imgSrc="adev/src/assets/images/overview.svg"> <!-- markdownlint-disable-line --> Learn about different ways you can optimize the performance of your application. </docs-decorative-header> One of the top priorities of any developer is ensuring that their application is as per...
{ "end_byte": 1909, "start_byte": 0, "url": "https://github.com/angular/angular/blob/main/adev/src/content/guide/performance/overview.md" }
angular/adev/src/content/guide/performance/BUILD.bazel_0_258
load("//adev/shared-docs:index.bzl", "generate_guides") generate_guides( name = "performance", srcs = glob([ "*.md", ]), data = [ "//adev/src/assets/images:overview.svg", ], visibility = ["//adev:__subpackages__"], )
{ "end_byte": 258, "start_byte": 0, "url": "https://github.com/angular/angular/blob/main/adev/src/content/guide/performance/BUILD.bazel" }
angular/adev/src/content/guide/i18n/format-data-locale.md_0_2034
# Format data based on locale Angular provides the following built-in data transformation [pipes](guide/templates/pipes). The data transformation pipes use the [`LOCALE_ID`][ApiCoreLocaleId] token to format data based on rules of each locale. | Data transformation pipe | Details | |:--- ...
{ "end_byte": 2034, "start_byte": 0, "url": "https://github.com/angular/angular/blob/main/adev/src/content/guide/i18n/format-data-locale.md" }
angular/adev/src/content/guide/i18n/translation-files.md_0_8293
# Work with translation files After you prepare a component for translation, use the [`extract-i18n`][CliExtractI18n] [Angular CLI][CliMain] command to extract the marked text in the component into a *source language* file. The marked text includes text marked with `i18n`, attributes marked with `i18n-`*attribute*, a...
{ "end_byte": 8293, "start_byte": 0, "url": "https://github.com/angular/angular/blob/main/adev/src/content/guide/i18n/translation-files.md" }
angular/adev/src/content/guide/i18n/translation-files.md_8293_14451
## Translate plurals Add or remove plural cases as needed for each language. HELPFUL: For language plural rules, see [CLDR plural rules][GithubUnicodeOrgCldrStagingChartsLatestSupplementalLanguagePluralRulesHtml]. ### `minute` `plural` example To translate a `plural`, translate the ICU format match values. * `just...
{ "end_byte": 14451, "start_byte": 8293, "url": "https://github.com/angular/angular/blob/main/adev/src/content/guide/i18n/translation-files.md" }
angular/adev/src/content/guide/i18n/manage-marked-text.md_0_4780
# Manage marked text with custom IDs The Angular extractor generates a file with a translation unit entry each of the following instances. * Each `i18n` attribute in a component template * Each [`$localize`][ApiLocalizeInitLocalize] tagged message string in component code As described in [How meanings control text e...
{ "end_byte": 4780, "start_byte": 0, "url": "https://github.com/angular/angular/blob/main/adev/src/content/guide/i18n/manage-marked-text.md" }
angular/adev/src/content/guide/i18n/overview.md_0_2681
# Angular Internationalization *Internationalization*, sometimes referenced as i18n, is the process of designing and preparing your project for use in different locales around the world. *Localization* is the process of building versions of your project for different locales. The localization process includes the foll...
{ "end_byte": 2681, "start_byte": 0, "url": "https://github.com/angular/angular/blob/main/adev/src/content/guide/i18n/overview.md" }
angular/adev/src/content/guide/i18n/example.md_0_976
# Example Angular Internationalization application <!-- ## Explore the translated example application --> <!-- Explore the sample application with French translations used in the [Angular Internationalization][GuideI18nOverview] guide: --> <!-- TODO: link to GitHub --> <!-- <docs-code live path="adev/src/content/exam...
{ "end_byte": 976, "start_byte": 0, "url": "https://github.com/angular/angular/blob/main/adev/src/content/guide/i18n/example.md" }
angular/adev/src/content/guide/i18n/prepare.md_0_9006
# Prepare component for translation To prepare your project for translation, complete the following actions. - Use the `i18n` attribute to mark text in component templates - Use the `i18n-` attribute to mark attribute text strings in component templates - Use the `$localize` tagged message string to mark text strings...
{ "end_byte": 9006, "start_byte": 0, "url": "https://github.com/angular/angular/blob/main/adev/src/content/guide/i18n/prepare.md" }
angular/adev/src/content/guide/i18n/prepare.md_9006_17947
## ICU expressions ICU expressions help you mark alternate text in component templates to meet conditions. An ICU expression includes a component property, an ICU clause, and the case statements surrounded by open curly brace \(`{`\) and close curly brace \(`}`\) characters. <!--todo: replace with docs-code --> <doc...
{ "end_byte": 17947, "start_byte": 9006, "url": "https://github.com/angular/angular/blob/main/adev/src/content/guide/i18n/prepare.md" }
angular/adev/src/content/guide/i18n/prepare.md_17947_19622
## What's next <docs-pill-row> <docs-pill href="guide/i18n/translation-files" title="Work with translation files"/> </docs-pill-row> [ApiLocalizeInitLocalize]: api/localize/init/$localize '$localize | init - localize - API | Angular' [GuideI18nCommonPrepareMarkAlternatesAndNestedExpressions]: guide/i18n/prepare#ma...
{ "end_byte": 19622, "start_byte": 17947, "url": "https://github.com/angular/angular/blob/main/adev/src/content/guide/i18n/prepare.md" }
angular/adev/src/content/guide/i18n/add-package.md_0_1954
# Add the localize package To take advantage of the localization features of Angular, use the [Angular CLI][CliMain] to add the `@angular/localize` package to your project. To add the `@angular/localize` package, use the following command to update the `package.json` and TypeScript configuration files in your project...
{ "end_byte": 1954, "start_byte": 0, "url": "https://github.com/angular/angular/blob/main/adev/src/content/guide/i18n/add-package.md" }
angular/adev/src/content/guide/i18n/deploy.md_0_2399
# Deploy multiple locales If `myapp` is the directory that contains the distributable files of your project, you typically make different versions available for different locales in locale directories. For example, your French version is located in the `myapp/fr` directory and the Spanish version is located in the `my...
{ "end_byte": 2399, "start_byte": 0, "url": "https://github.com/angular/angular/blob/main/adev/src/content/guide/i18n/deploy.md" }
angular/adev/src/content/guide/i18n/import-global-variants.md_0_1213
# Import global variants of the locale data 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 --> <docs-code language="shell"> ng build --localize </docs-code> HELPFUL: The initial installation...
{ "end_byte": 1213, "start_byte": 0, "url": "https://github.com/angular/angular/blob/main/adev/src/content/guide/i18n/import-global-variants.md" }
angular/adev/src/content/guide/i18n/merge.md_0_9284
# Merge translations into the application To merge the completed translations into your project, complete the following actions 1. Use the [Angular CLI][CliMain] to build a copy of the distributable files of your project 1. Use the `"localize"` option to replace all of the i18n messages with the valid translations an...
{ "end_byte": 9284, "start_byte": 0, "url": "https://github.com/angular/angular/blob/main/adev/src/content/guide/i18n/merge.md" }
angular/adev/src/content/guide/i18n/merge.md_9284_10869
## What's next <docs-pill-row> <docs-pill href="guide/i18n/deploy" title="Deploy multiple locales"/> </docs-pill-row> [ApiLocalizeInitLocalize]: api/localize/init/$localize "$localize | init - localize - API | Angular" [CliMain]: cli "CLI Overview and Command Reference | Angular" [CliBuild]: cli/build "ng build | ...
{ "end_byte": 10869, "start_byte": 9284, "url": "https://github.com/angular/angular/blob/main/adev/src/content/guide/i18n/merge.md" }
angular/adev/src/content/guide/i18n/BUILD.bazel_0_1020
load("//adev/shared-docs:index.bzl", "generate_guides") generate_guides( name = "i18n", srcs = glob([ "*.md", ]), data = [ "//adev/src/content/examples/i18n:angular.json", "//adev/src/content/examples/i18n:doc-files/apache2.conf", "//adev/src/content/examples/i18n:doc-fi...
{ "end_byte": 1020, "start_byte": 0, "url": "https://github.com/angular/angular/blob/main/adev/src/content/guide/i18n/BUILD.bazel" }
angular/adev/src/content/guide/i18n/locale-id.md_0_3140
# Refer to locales by ID Angular uses the Unicode *locale identifier* \(Unicode locale ID\) to find the correct locale data for internationalization of text strings. <docs-callout title="Unicode locale ID"> * A locale ID conforms to the [Unicode Common Locale Data Repository (CLDR) core specification][UnicodeCldrDev...
{ "end_byte": 3140, "start_byte": 0, "url": "https://github.com/angular/angular/blob/main/adev/src/content/guide/i18n/locale-id.md" }
angular/adev/src/content/guide/animations/overview.md_0_3625
# Introduction to Angular animations Animation provides the illusion of motion: HTML elements change styling over time. Well-designed animations can make your application more fun and straightforward to use, but they aren't just cosmetic. Animations can improve your application and user experience in a number of ways:...
{ "end_byte": 3625, "start_byte": 0, "url": "https://github.com/angular/angular/blob/main/adev/src/content/guide/animations/overview.md" }
angular/adev/src/content/guide/animations/overview.md_3625_10942
## Animating a transition Let's animate a transition that changes a single HTML element from one state to another. For example, you can specify that a button displays either **Open** or **Closed** based on the user's last action. When the button is in the `open` state, it's visible and yellow. When it's the `closed` s...
{ "end_byte": 10942, "start_byte": 3625, "url": "https://github.com/angular/angular/blob/main/adev/src/content/guide/animations/overview.md" }
angular/adev/src/content/guide/animations/overview.md_10942_18604
efining animations and attaching them to the HTML template Animations are defined in the metadata of the component that controls the HTML element to be animated. Put the code that defines your animations under the `animations:` property within the `@Component()` decorator. <docs-code header="src/app/open-close.compon...
{ "end_byte": 18604, "start_byte": 10942, "url": "https://github.com/angular/angular/blob/main/adev/src/content/guide/animations/overview.md" }