id stringlengths 6 6 | text stringlengths 20 17.2k | title stringclasses 1
value |
|---|---|---|
003814 | import {bootstrapApplication} from '@angular/platform-browser';
import {provideAnimations} from '@angular/platform-browser/animations';
import {provideRouter} from '@angular/router';
import {AppComponent} from './app/app.component';
bootstrapApplication(AppComponent, {
providers: [
provideAnimations(),
prov... | |
004063 | <!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Example</title>
<base href="/">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link href="https://fonts.googleapis.com/css2?family=Roboto:wght@300;400;500&display=swap" rel="stylesheet">
<link href="https://fonts.go... | |
004099 | /*!
* @license
* Copyright Google LLC All Rights Reserved.
*
* Use of this source code is governed by an MIT-style license that can be
* found in the LICENSE file at https://angular.dev/license
*/
import {isPlatformBrowser} from '@angular/common';
import {InjectionToken, PLATFORM_ID, inject} from '@angular/core'... | |
004131 | // TODO: Continue organizing and refactoring this file
@use '@angular/material' as mat;
// Using disable-next-line to avoid stylelint errors - these imports are necessary
// TODO: Is there another way to prevent these linting errors?
// stylelint-disable-next-line @angular/no-unused-import
@use '_colors';
// stylelint... | |
004134 | @mixin external-link-with-icon() {
&::after {
display: inline-block;
content: '\e89e'; // codepoint for "open_in_new"
font-family: 'Material Symbols Outlined';
margin-left: 0.2rem;
vertical-align: middle;
}
} | |
004197 | import {ChangeDetectionStrategy, Component, inject, input, OnInit, signal} from '@angular/core';
import {ExternalLink} from '../../directives';
import {LOCAL_STORAGE} from '../../providers';
import {IconComponent} from '../icon/icon.component';
export const STORAGE_KEY_PREFIX = 'docs-was-closed-top-banner-';
@Compone... | |
004266 | /*!
* @license
* Copyright Google LLC All Rights Reserved.
*
* Use of this source code is governed by an MIT-style license that can be
* found in the LICENSE file at https://angular.dev/license
*/
import {mergeApplicationConfig, ApplicationConfig} from '@angular/core';
import {provideServerRendering} from '@angu... | |
004270 | /*!
* @license
* Copyright Google LLC All Rights Reserved.
*
* Use of this source code is governed by an MIT-style license that can be
* found in the LICENSE file at https://angular.dev/license
*/
import {DOCUMENT, isPlatformBrowser} from '@angular/common';
import {
ChangeDetectionStrategy,
Component,
inje... | |
004277 | /*!
* @license
* Copyright Google LLC All Rights Reserved.
*
* Use of this source code is governed by an MIT-style license that can be
* found in the LICENSE file at https://angular.dev/license
*/
import {
ChangeDetectionStrategy,
Component,
DestroyRef,
OnInit,
PLATFORM_ID,
computed,
inject,
sign... | |
004282 | /*!
* @license
* Copyright Google LLC All Rights Reserved.
*
* Use of this source code is governed by an MIT-style license that can be
* found in the LICENSE file at https://angular.dev/license
*/
import {
ChangeDetectionStrategy,
Component,
inject,
OnInit,
PLATFORM_ID,
ViewChild,
} from '@angular/co... | |
004283 | /*!
* @license
* Copyright Google LLC All Rights Reserved.
*
* Use of this source code is governed by an MIT-style license that can be
* found in the LICENSE file at https://angular.dev/license
*/
import {CdkMenu, CdkMenuItem, CdkMenuTrigger} from '@angular/cdk/menu';
import {DOCUMENT, Location, isPlatformBrowse... | |
004285 | /*!
* @license
* Copyright Google LLC All Rights Reserved.
*
* Use of this source code is governed by an MIT-style license that can be
* found in the LICENSE file at https://angular.dev/license
*/
import {ComponentFixture, TestBed} from '@angular/core/testing';
import {Navigation} from './navigation.component';... | |
004300 | /*!
* @license
* Copyright Google LLC All Rights Reserved.
*
* Use of this source code is governed by an MIT-style license that can be
* found in the LICENSE file at https://angular.dev/license
*/
import {DOCUMENT, isPlatformBrowser} from '@angular/common';
import {Injectable, PLATFORM_ID, inject, signal} from '... | |
004319 | /*!
* @license
* Copyright Google LLC All Rights Reserved.
*
* Use of this source code is governed by an MIT-style license that can be
* found in the LICENSE file at https://angular.dev/license
*/
import {DOCUMENT, isPlatformBrowser} from '@angular/common';
import {
AfterViewInit,
ChangeDetectionStrategy,
... | |
004329 | /*!
* @license
* Copyright Google LLC All Rights Reserved.
*
* Use of this source code is governed by an MIT-style license that can be
* found in the LICENSE file at https://angular.dev/license
*/
// import {ComponentFixture, TestBed} from '@angular/core/testing';
// import Home from './home.component';
// impo... | |
004366 | /*!
* @license
* Copyright Google LLC All Rights Reserved.
*
* Use of this source code is governed by an MIT-style license that can be
* found in the LICENSE file at https://angular.dev/license
*/
import {DOCS_VIEWER_SELECTOR, DocViewer, WINDOW} from '@angular/docs';
import {Component, Input, signal} from '@ang... | |
004380 | possibleIn: 900,
necessaryAsOf: 1000,
level: ApplicationComplexity.Medium,
step: 'debug',
action:
'With Angular 9 Ivy is now the default rendering engine, for any compatibility problems that might arise, read the [Ivy compatibility guide](https://v9.angular.io/guide/ivy-compatibility).',
},
{
... | |
004386 | possibleIn: 1500,
necessaryAsOf: 1500,
level: ApplicationComplexity.Medium,
step: 'v15 iframe',
action:
"Existing `<iframe>` instances might have security-sensitive attributes applied to them as an attribute or property binding. These security-sensitive attributes can occur in a template or in a d... | |
004387 | possibleIn: 1600,
necessaryAsOf: 1600,
level: ApplicationComplexity.Medium,
step: 'v16 withServerTransition',
action:
"If you're running multiple Angular apps on the same page and you're using `BrowserModule.withServerTransition({ appId: 'serverApp' })` make sure you set the `APP_ID` instead since... | |
004388 | possibleIn: 1700,
necessaryAsOf: 1700,
level: ApplicationComplexity.Advanced,
step: 'v17 ngDoCheck dynamic components',
action:
'For dynamically instantiated components we now execute `ngDoCheck` during change detection if the component is marked as dirty. You may need to update your tests or logi... | |
004424 | /*!
* @license
* Copyright Google LLC All Rights Reserved.
*
* Use of this source code is governed by an MIT-style license that can be
* found in the LICENSE file at https://angular.dev/license
*/
import {DOCUMENT, isPlatformBrowser} from '@angular/common';
import {
DestroyRef,
EnvironmentInjector,
Injecta... | |
004515 | # Deferrable Views
## Overview
Deferrable views can be used in component template to defer the loading of select dependencies within that template. Those dependencies include components, directives, and pipes, and any associated CSS. To use this feature, you can declaratively wrap a section of your template in a `@de... | |
004516 | ## Triggers
When a `@defer` block is triggered, it replaces placeholder content with lazily loaded content. There are two options for configuring when this swap is triggered: `on` and `when`.
<a id="on"></a>
`on` specifies a trigger condition using a trigger from the list of available triggers below. An example would... | |
004517 | # Hydration
## What is hydration
Hydration is the process that restores the server-side rendered application on the client. This includes things like reusing the server rendered DOM structures, persisting the application state, transferring application data that was retrieved already by the server, and other processe... | |
004519 | # Prerendering (SSG)
Prerendering, commonly referred to as Static Site Generation (SSG), represents the method by which pages are rendered to static HTML files during the build process.
Prerendering maintains the same performance benefits of [server-side rendering (SSR)](guide/ssr#why-use-server-side-rendering) but a... | |
004520 | # Getting started with NgOptimizedImage
The `NgOptimizedImage` directive makes it easy to adopt performance best practices for loading images.
The directive ensures that the loading of the [Largest Contentful Paint (LCP)](http://web.dev/lcp) image is prioritized by:
* Automatically setting the `fetchpriority` attrib... | |
004524 | # Server-side rendering
Server-side rendering (SSR) is a process that involves rendering pages on the server, resulting in initial HTML content which contains initial page state. Once the HTML content is delivered to a browser, Angular initializes the application and utilizes the data contained within the HTML.
## Wh... | |
004532 | # Angular without ZoneJS (Zoneless)
## Why use Zoneless?
The main advantages to removing ZoneJS as a dependency are:
- **Improved performance**: ZoneJS uses DOM events and async tasks as indicators of when application state _might_ have updated and subsequently triggers application synchronization to run change dete... | |
004534 | <docs-decorative-header title="Built-in directives" imgSrc="adev/src/assets/images/directives.svg"> <!-- markdownlint-disable-line -->
Directives are classes that add additional behavior to elements in your Angular applications.
</docs-decorative-header>
Use Angular's built-in directives to manage forms, lists, styles... | |
004535 | ## Adding or removing an element with `NgIf`
Add or remove an element by applying an `NgIf` directive to a host element.
When `NgIf` is `false`, Angular removes an element and its descendants from the DOM.
Angular then disposes of their components, which frees up memory and resources.
### Import `NgIf` in the compon... | |
004539 | # Structural directives
Structural directives are directives applied to an `<ng-template>` element that conditionally or repeatedly render the content of that `<ng-template>`.
## Example use case
In this guide you'll build a structural directive which fetches data from a given data source and renders its template wh... | |
004541 | # Singleton services
A singleton service is a service for which only one instance exists in an application.
## Providing a singleton service
There are two ways to make a service a singleton in Angular:
* Set the `providedIn` property of the `@Injectable()` to `"root"`
* Include the service in the `AppModule` or in ... | |
004543 | Step-by-step setup
Setting up a lazy-loaded feature module requires two main steps:
1. Create the feature module with the Angular CLI, using the `--route` flag.
1. Configure the routes.
### Set up an application
If you don't already have an application, follow the following steps to create one with the Angular CLI.... | |
004544 | # Verify lazy loading
You can verify that a module is indeed being lazy loaded with the Chrome developer tools.
In Chrome, open the developer tools by pressing <kbd>⌘ Cmd</kbd>+<kbd>Option</kbd>+<kbd>i</kbd> on a Mac or <kbd>Ctrl</kbd>+<kbd>Shift</kbd>+<kbd>j</kbd> on a PC and go to the Network Tab.
<img alt="lazy lo... | |
004546 | # NgModules
**NgModules** configure the injector, the compiler and help organize related things together.
An NgModule is a class marked by the `@NgModule` decorator.
`@NgModule` takes a metadata object that describes how to compile a component's template and how to create an injector at runtime.
It identifies the mod... | |
004547 | # Providing dependencies in modules
A provider is an instruction to the [Dependency Injection](guide/di) system on how to obtain a value for a dependency.
Most of the time, these dependencies are services that you create and provide.
## Providing a service
If you already have an application that was created with the... | |
004548 | # NgModule API
At a high level, NgModules are a way to organize Angular applications and they accomplish this through the metadata in the `@NgModule` decorator.
The metadata falls into three categories:
| Category | Details |
|:--- |:--- |
| Static | Compiler... | |
004549 | # Launching your app with a root module
An NgModule describes how the application parts fit together.
Every application has at least one Angular module, the *root* module, which must be present for bootstrapping the application on launch.
By convention and by default, this NgModule is named `AppModule`.
When you use ... | |
004550 | # NgModule FAQ
NgModules help organize an application into cohesive blocks of functionality.
This page answers the questions many developers ask about NgModule design and implementation.
## What classes should I add to the `declarations` array?
Add [declarable](guide/ngmodules/bootstrapping#the-declarations-array) ... | |
004551 | service provided in a feature module visible everywhere?
Providers listed in the `@NgModule.providers` of a bootstrapped module have application scope.
Adding a service provider to `@NgModule.providers` effectively publishes the service to the entire application.
When you import an NgModule, Angular adds the module's... | |
004552 | bad if a shared module provides a service to a lazy-loaded module?
### The eagerly loaded scenario
When an eagerly loaded module provides a service, for example a `UserService`, that service is available application-wide.
If the root module provides `UserService` and imports another module that provides the same `Use... | |
004553 | # Guidelines for creating NgModules
This topic provides a conceptual overview of the different categories of NgModules you can create in order to organize your code in a modular structure.
These categories are not cast in stone —they are suggestions.
You may want to create NgModules for other purposes, or combine the ... | |
004554 | # Frequently-used modules
A Module-based Angular application needs at least one module that serves as the root module.
As you add features to your app, you can add them in modules.
The following are frequently used Angular modules with examples of some of the things they contain:
| NgModule | Import it f... | |
004555 | # Feature modules
Feature modules are NgModules for the purpose of organizing code.
As your application grows, you can organize code relevant for a specific feature.
This helps apply clear boundaries for features.
With feature modules, you can keep code related to a specific functionality or feature separate from oth... | |
004557 | # Sharing modules
Creating shared modules allows you to organize and streamline your code.
You can put commonly used directives, pipes, and components into one module and then import just that module wherever you need it in other parts of your application.
Consider the following module from an imaginary app:
<docs-c... | |
004559 | # Creating an injectable service
Service is a broad category encompassing any value, function, or feature that an application needs.
A service is typically a class with a narrow, well-defined purpose.
A component is one type of class that can use DI.
Angular distinguishes components from services to increase modulari... | |
004560 | # Configuring dependency providers
The previous sections described how to use class instances as dependencies.
Aside from classes, you can also use values such as `boolean`, `string`, `Date`, and objects as dependencies.
Angular provides the necessary APIs to make the dependency configuration flexible, so you can make... | |
004562 | # Understanding dependency injection
Dependency injection, or DI, is one of the fundamental concepts in Angular. DI is wired into the Angular framework and allows classes with Angular decorators, such as Components, Directives, Pipes, and Injectables, to configure dependencies that they need.
Two main roles exist in ... | |
004563 | # Injection context
The dependency injection (DI) system relies internally on a runtime context where the current injector is available.
This means that injectors can only work when code is executed in such a context.
The injection context is available in these situations:
* During construction (via the `constructor... | |
004564 | # Hierarchical injectors
Injectors in Angular have rules that you can leverage to achieve the desired visibility of injectables in your applications.
By understanding these rules, you can determine whether to declare a provider at the application level, in a Component, or in a Directive.
The applications you build wi... | |
004571 | ses
The ability to configure one or more providers at different levels opens up useful possibilities.
### Scenario: service isolation
Architectural reasons may lead you to restrict access to a service to the application domain where it belongs.
For example, consider we build a `VillainsListComponent` that displays a... | |
004576 | ## Data flow in forms
When an application contains a form, Angular must keep the view in sync with the component model and the component model in sync with the view.
As users change values and make selections through the view, the new values must be reflected in the data model.
Similarly, when the program logic change... | |
004581 | ing asynchronous validators
Asynchronous validators implement the `AsyncValidatorFn` and `AsyncValidator` interfaces.
These are very similar to their synchronous counterparts, with the following differences.
* The `validate()` functions must return a Promise or an observable,
* The observable returned must be finite,... | |
004584 | ### Updating parts of the data model
When updating the value for a form group instance that contains multiple controls, you might only want to update parts of the model.
This section covers how to update specific parts of a form control data model.
There are two ways to update the model value:
| Methods | Det... | |
004585 | ## Creating dynamic forms
`FormArray` is an alternative to `FormGroup` for managing any number of unnamed controls.
As with form group instances, you can dynamically insert and remove controls from form array instances, and the form array instance value and validation status is calculated from its child controls.
Howe... | |
004586 | # Building a template-driven form
This tutorial shows you how to create a template-driven form. The control elements in the form are bound to data properties that have input validation. The input validation helps maintain data integrity and styling to improve the user experience.
Template-driven forms use [two-way da... | |
004587 | Bind input controls to data properties
The next step is to bind the input controls to the corresponding `Actor` properties with two-way data binding, so that they respond to user input by updating the data model, and also respond to programmatic changes in the data by updating the display.
The `ngModel` directive dec... | |
004588 | Track control states
Adding the `NgModel` directive to a control adds class names to the control that describe its state.
These classes can be used to change a control's style based on its state.
The following table describes the class names that Angular applies based on the control's state.
| States ... | |
004591 | # Typed Forms
As of Angular 14, reactive forms are strictly typed by default.
As background for this guide, you should already be familiar with [Angular Reactive Forms](guide/forms/reactive-forms).
## Overview of Typed Forms
<docs-video src="https://www.youtube.com/embed/L-odCf4MfJc" alt="Typed Forms in Angular" />... | |
004592 | # RxJS Interop
IMPORTANT: The RxJS Interop package is available for [developer preview](reference/releases#developer-preview). It's ready for you to try, but it might change before it is stable.
Angular's `@angular/core/rxjs-interop` package provides useful utilities to integrate [Angular Signals](guide/signals) with... | |
004594 | <docs-decorative-header title="Angular Signals" imgSrc="adev/src/assets/images/signals.svg"> <!-- markdownlint-disable-line -->
Angular Signals is a system that granularly tracks how and where your state is used throughout an application, allowing the framework to optimize rendering updates.
</docs-decorative-header>
... | |
004595 | ## Advanced topics
### Signal equality functions
When creating a signal, you can optionally provide an equality function, which will be used to check whether the new value is actually different than the previous one.
```ts
import _ from 'lodash';
const data = signal(['test'], {equal: _.isEqual});
// Even though th... | |
004597 | # Signal inputs
Signal inputs allow values to be bound from parent components.
Those values are exposed using a `Signal` and can change during the lifecycle of your component.
Angular supports two variants of inputs:
**Optional inputs**
Inputs are optional by default, unless you use `input.required`.
You can specify... | |
004605 | # 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... | |
004609 | # 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 ... | |
004611 | # 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... | |
004613 | # 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)... | |
004614 | ## 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... | |
004619 | ## 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... | |
004623 | 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">
... | |
004625 | # 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... | |
004626 | ### 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... | |
004632 | # 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 ... | |
004633 | # 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... | |
004636 | # 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... | |
004639 | # 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... | |
004642 | # 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... | |
004644 | # 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... | |
004645 | # 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... | |
004646 | ## 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... | |
004647 | # 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... | |
004649 | # 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... | |
004651 | # 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),... | |
004652 | 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, `;... | |
004654 | <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... | |
004657 | # 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 ... | |
004659 | # 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... | |
004661 | # 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... | |
004662 | # 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... | |
004664 | # 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... | |
004666 | # 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... | |
004670 | # 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... | |
004671 | ## 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... | |
004672 | ## 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... | |
004673 | ## `<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... | |
004674 | # 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... | |
004675 | 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 |
|:--- |:--- |
| [`Navigation... | |
004678 | ## 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... | |
004679 | <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... | |
004690 | # 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... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.