_id stringlengths 21 254 | text stringlengths 1 93.7k | metadata dict |
|---|---|---|
angular/adev/src/app/editor/terminal/terminal.component.spec.ts_0_1819 | /*!
* @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 {By} from '@angular/platform-browser';
impo... | {
"end_byte": 1819,
"start_byte": 0,
"url": "https://github.com/angular/angular/blob/main/adev/src/app/editor/terminal/terminal.component.spec.ts"
} |
angular/adev/src/app/editor/terminal/terminal.component.scss_0_444 | // Note: disabling the @angular/no-import rule here as it's meant to disable
// SASS imports, here we're importing a CSS asset
//
// stylelint-disable-next-line @angular/no-import
@import '@xterm/xterm/css/xterm.css';
.docs-tutorial-terminal {
display: block;
// adjust height for terminal tabs
height: calc(100% ... | {
"end_byte": 444,
"start_byte": 0,
"url": "https://github.com/angular/angular/blob/main/adev/src/app/editor/terminal/terminal.component.scss"
} |
angular/adev/src/app/editor/terminal/terminal.component.html_0_57 | <div #terminalOutput class="adev-terminal-output"></div>
| {
"end_byte": 57,
"start_byte": 0,
"url": "https://github.com/angular/angular/blob/main/adev/src/app/editor/terminal/terminal.component.html"
} |
angular/adev/src/app/editor/preview/preview-error.component.scss_0_695 | :host {
margin: 5% auto;
}
.adev-preview-error {
border: 1px solid var(--senary-contrast);
border-radius: 0.25rem;
padding: 1rem;
p {
display: flex;
gap: 0.5rem;
font-weight: 600;
margin-top: 0;
&::before {
content: 'error';
font-family: var(--icons);
color: var(--oran... | {
"end_byte": 695,
"start_byte": 0,
"url": "https://github.com/angular/angular/blob/main/adev/src/app/editor/preview/preview-error.component.scss"
} |
angular/adev/src/app/editor/preview/preview-error.component.ts_0_884 | /*!
* @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} from '@angular/core';
import {isFirefox, isIos} from '@angular/d... | {
"end_byte": 884,
"start_byte": 0,
"url": "https://github.com/angular/angular/blob/main/adev/src/app/editor/preview/preview-error.component.ts"
} |
angular/adev/src/app/editor/preview/preview-error.component.html_0_1113 | <div class="adev-preview-error docs-light-mode docs-mini-scroll-track">
@switch (true) {
@case (error()?.type === ErrorType.UNSUPPORTED_BROWSER_ENVIRONMENT) {
@if(isIos) {
<p>Open angular.dev on desktop to code in your browser.</p>
} @else if(isFirefox) {
<p>
We're currently ... | {
"end_byte": 1113,
"start_byte": 0,
"url": "https://github.com/angular/angular/blob/main/adev/src/app/editor/preview/preview-error.component.html"
} |
angular/adev/src/app/editor/preview/preview-error.component.spec.ts_0_639 | /*!
* @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 {PreviewError} from './preview-error.compon... | {
"end_byte": 639,
"start_byte": 0,
"url": "https://github.com/angular/angular/blob/main/adev/src/app/editor/preview/preview-error.component.spec.ts"
} |
angular/adev/src/app/editor/preview/preview.component.scss_0_918 | :host {
display: block;
.docs-dark-mode & {
.adev-embedded-editor-preview-container {
background: var(--gray-100);
}
}
// account for tabs height
height: calc(100% - 50px);
// If preview has error, make it scrollable
&:has(.adev-preview-error) {
.adev-embedded-editor-preview-container ... | {
"end_byte": 918,
"start_byte": 0,
"url": "https://github.com/angular/angular/blob/main/adev/src/app/editor/preview/preview.component.scss"
} |
angular/adev/src/app/editor/preview/preview.component.spec.ts_0_4974 | /*!
* @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 {TestBed} from '@angular/core/testing';
import {DebugElement, signal} from '@angular/core';
import {By} from ... | {
"end_byte": 4974,
"start_byte": 0,
"url": "https://github.com/angular/angular/blob/main/adev/src/app/editor/preview/preview.component.spec.ts"
} |
angular/adev/src/app/editor/preview/preview.component.ts_0_2631 | /*!
* @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 {NgComponentOutlet} from '@angular/common';
import {
AfterViewInit,
ChangeDetectionStrategy,
ChangeDete... | {
"end_byte": 2631,
"start_byte": 0,
"url": "https://github.com/angular/angular/blob/main/adev/src/app/editor/preview/preview.component.ts"
} |
angular/adev/src/app/editor/preview/preview.component.html_0_1343 | <div class="adev-embedded-editor-preview-container">
@if (loadingProgressValue() !== loadingEnum.ERROR) {
<iframe
#preview
class="adev-embedded-editor-preview"
allow="cross-origin-isolated"
title="Editor preview"
></iframe>
} @if (previewErrorComponent) {
<ng-container
*ngComponentOutlet="... | {
"end_byte": 1343,
"start_byte": 0,
"url": "https://github.com/angular/angular/blob/main/adev/src/app/editor/preview/preview.component.html"
} |
angular/adev/src/content/kitchen-sink.md_0_6543 | <docs-decorative-header title="Kitchen sink" imgSrc="assets/images/components.svg"> <!-- markdownlint-disable-line -->
This is a visual list of all custom components and styles for Angular.dev.
</docs-decorative-header>
As a design system, this page contains visual and Markdown authoring guidance for:
* Custom Angula... | {
"end_byte": 6543,
"start_byte": 0,
"url": "https://github.com/angular/angular/blob/main/adev/src/content/kitchen-sink.md"
} |
angular/adev/src/content/kitchen-sink.md_6543_14644 | ## Code
You can display `code` using the built in triple backtick:
```ts
example code
```
Or using the `<docs-code>` element.
<docs-code header="Your first example" language="ts" linenums>
import { Component } from '@angular/core';
@Component({
selector: 'example-code',
template: '<h1>Hello World!</h1>',
})
ex... | {
"end_byte": 14644,
"start_byte": 6543,
"url": "https://github.com/angular/angular/blob/main/adev/src/content/kitchen-sink.md"
} |
angular/adev/src/content/error.md_0_168 | # Page Not Found 🙃
If you think this is a mistake, please [open an issue](https://github.com/angular/angular/issues/new?template=3-docs-bug.yaml) so we can fix it.
| {
"end_byte": 168,
"start_byte": 0,
"url": "https://github.com/angular/angular/blob/main/adev/src/content/error.md"
} |
angular/adev/src/content/BUILD.bazel_0_198 | load("//adev/shared-docs:index.bzl", "generate_guides")
generate_guides(
name = "content",
srcs = [
"error.md",
],
data = [],
visibility = ["//adev:__subpackages__"],
)
| {
"end_byte": 198,
"start_byte": 0,
"url": "https://github.com/angular/angular/blob/main/adev/src/content/BUILD.bazel"
} |
angular/adev/src/content/guide/defer.md_0_5433 | # 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... | {
"end_byte": 5433,
"start_byte": 0,
"url": "https://github.com/angular/angular/blob/main/adev/src/content/guide/defer.md"
} |
angular/adev/src/content/guide/defer.md_5433_14304 | ## 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... | {
"end_byte": 14304,
"start_byte": 5433,
"url": "https://github.com/angular/angular/blob/main/adev/src/content/guide/defer.md"
} |
angular/adev/src/content/guide/hydration.md_0_9206 | # 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... | {
"end_byte": 9206,
"start_byte": 0,
"url": "https://github.com/angular/angular/blob/main/adev/src/content/guide/hydration.md"
} |
angular/adev/src/content/guide/hydration.md_9206_12659 | ## Errors
There are several hydration related errors you may encounter ranging from node mismatches to cases when the `ngSkipHydration` was used on an invalid host node. The most common error case that may occur is due to direct DOM manipulation using native APIs that results in hydration being unable to find or match... | {
"end_byte": 12659,
"start_byte": 9206,
"url": "https://github.com/angular/angular/blob/main/adev/src/content/guide/hydration.md"
} |
angular/adev/src/content/guide/prerendering.md_0_3886 | # 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... | {
"end_byte": 3886,
"start_byte": 0,
"url": "https://github.com/angular/angular/blob/main/adev/src/content/guide/prerendering.md"
} |
angular/adev/src/content/guide/image-optimization.md_0_7202 | # 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... | {
"end_byte": 7202,
"start_byte": 0,
"url": "https://github.com/angular/angular/blob/main/adev/src/content/guide/image-optimization.md"
} |
angular/adev/src/content/guide/image-optimization.md_7202_10892 | sing placeholders
### Automatic placeholders
NgOptimizedImage can display an automatic low-resolution placeholder for your image if you're using a CDN or image host that provides automatic image resizing. Take advantage of this feature by adding the `placeholder` attribute to your image:
<docs-code format="typescrip... | {
"end_byte": 10892,
"start_byte": 7202,
"url": "https://github.com/angular/angular/blob/main/adev/src/content/guide/image-optimization.md"
} |
angular/adev/src/content/guide/image-optimization.md_10892_17057 | erformance Features
NgOptimizedImage includes a number of features designed to improve loading performance in your app. These features are described in this section.
### Add resource hints
A [`preconnect` resource hint](https://web.dev/preconnect-and-dns-prefetch) for your image origin ensures that the LCP image loa... | {
"end_byte": 17057,
"start_byte": 10892,
"url": "https://github.com/angular/angular/blob/main/adev/src/content/guide/image-optimization.md"
} |
angular/adev/src/content/guide/image-optimization.md_17057_25896 | onfiguring an image loader for `NgOptimizedImage`
A "loader" is a function that generates an [image transformation URL](https://web.dev/image-cdns/#how-image-cdns-use-urls-to-indicate-optimization-options) for a given image file. When appropriate, `NgOptimizedImage` sets the size, format, and image quality transformat... | {
"end_byte": 25896,
"start_byte": 17057,
"url": "https://github.com/angular/angular/blob/main/adev/src/content/guide/image-optimization.md"
} |
angular/adev/src/content/guide/ssr.md_0_7166 | # 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... | {
"end_byte": 7166,
"start_byte": 0,
"url": "https://github.com/angular/angular/blob/main/adev/src/content/guide/ssr.md"
} |
angular/adev/src/content/guide/BUILD.bazel_0_827 | load("//adev/shared-docs:index.bzl", "generate_guides")
generate_guides(
name = "guide",
srcs = glob([
"*.md",
]),
data = [
"//adev/src/content/examples/elements:src/app/app.component.ts",
"//adev/src/content/examples/elements:src/app/popup.component.ts",
"//adev/src/con... | {
"end_byte": 827,
"start_byte": 0,
"url": "https://github.com/angular/angular/blob/main/adev/src/content/guide/BUILD.bazel"
} |
angular/adev/src/content/guide/elements.md_0_7626 | # Angular elements overview
_Angular elements_ are Angular components packaged as _custom elements_ \(also called Web Components\), a web standard for defining new HTML elements in a framework-agnostic way.
[Custom elements](https://developer.mozilla.org/docs/Web/Web_Components/Using_custom_elements) are a Web Platfo... | {
"end_byte": 7626,
"start_byte": 0,
"url": "https://github.com/angular/angular/blob/main/adev/src/content/guide/elements.md"
} |
angular/adev/src/content/guide/elements.md_7626_10776 | Typings for custom elements
Generic DOM APIs, such as `document.createElement()` or `document.querySelector()`, return an element type that is appropriate for the specified arguments.
For example, calling `document.createElement('a')` returns an `HTMLAnchorElement`, which TypeScript knows has an `href` property.
Simi... | {
"end_byte": 10776,
"start_byte": 7626,
"url": "https://github.com/angular/angular/blob/main/adev/src/content/guide/elements.md"
} |
angular/adev/src/content/guide/security.md_0_1872 | # Security
This topic describes Angular's built-in protections against common web-application vulnerabilities and attacks such as cross-site scripting attacks.
It doesn't cover application-level security, such as authentication and authorization.
For more information about the attacks and mitigations described below,... | {
"end_byte": 1872,
"start_byte": 0,
"url": "https://github.com/angular/angular/blob/main/adev/src/content/guide/security.md"
} |
angular/adev/src/content/guide/security.md_1872_10120 | ## Preventing cross-site scripting (XSS)
[Cross-site scripting (XSS)](https://en.wikipedia.org/wiki/Cross-site_scripting) enables attackers to inject malicious code into web pages.
Such code can then, for example, steal user and login data, or perform actions that impersonate the user.
This is one of the most common a... | {
"end_byte": 10120,
"start_byte": 1872,
"url": "https://github.com/angular/angular/blob/main/adev/src/content/guide/security.md"
} |
angular/adev/src/content/guide/security.md_10120_19973 | ntent security policy
Content Security Policy \(CSP\) is a defense-in-depth technique to prevent XSS.
To enable CSP, configure your web server to return an appropriate `Content-Security-Policy` HTTP header.
Read more about content security policy at the [Web Fundamentals guide](https://developers.google.com/web/fundam... | {
"end_byte": 19973,
"start_byte": 10120,
"url": "https://github.com/angular/angular/blob/main/adev/src/content/guide/security.md"
} |
angular/adev/src/content/guide/security.md_19973_26995 | P-level vulnerabilities
Angular has built-in support to help prevent two common HTTP vulnerabilities, cross-site request forgery \(CSRF or XSRF\) and cross-site script inclusion \(XSSI\).
Both of these must be mitigated primarily on the server side, but Angular provides helpers to make integration on the client side e... | {
"end_byte": 26995,
"start_byte": 19973,
"url": "https://github.com/angular/angular/blob/main/adev/src/content/guide/security.md"
} |
angular/adev/src/content/guide/zoneless.md_0_7604 | # 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... | {
"end_byte": 7604,
"start_byte": 0,
"url": "https://github.com/angular/angular/blob/main/adev/src/content/guide/zoneless.md"
} |
angular/adev/src/content/guide/directives/attribute-directives.md_0_9164 | # Attribute directives
Change the appearance or behavior of DOM elements and Angular components with attribute directives.
## Building an attribute directive
This section walks you through creating a highlight directive that sets the background color of the host element to yellow.
1. To create a directive, use the ... | {
"end_byte": 9164,
"start_byte": 0,
"url": "https://github.com/angular/angular/blob/main/adev/src/content/guide/directives/attribute-directives.md"
} |
angular/adev/src/content/guide/directives/overview.md_0_8931 | <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... | {
"end_byte": 8931,
"start_byte": 0,
"url": "https://github.com/angular/angular/blob/main/adev/src/content/guide/directives/overview.md"
} |
angular/adev/src/content/guide/directives/overview.md_8931_16862 | ## 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... | {
"end_byte": 16862,
"start_byte": 8931,
"url": "https://github.com/angular/angular/blob/main/adev/src/content/guide/directives/overview.md"
} |
angular/adev/src/content/guide/directives/overview.md_16862_20393 | ## Switching cases with `NgSwitch`
Like the JavaScript `switch` statement, `NgSwitch` displays one element from among several possible elements, based on a switch condition.
Angular puts only the selected element into the DOM.
<!--todo: API Flagged -->
`NgSwitch` is a set of three directives:
| `NgSwitch` directive... | {
"end_byte": 20393,
"start_byte": 16862,
"url": "https://github.com/angular/angular/blob/main/adev/src/content/guide/directives/overview.md"
} |
angular/adev/src/content/guide/directives/directive-composition-api.md_0_6051 | # Directive composition API
Angular directives offer a great way to encapsulate reusable behaviors— directives can apply
attributes, CSS classes, and event listeners to an element.
The *directive composition API* lets you apply directives to a component's host element from
*within* the component TypeScript class.
##... | {
"end_byte": 6051,
"start_byte": 0,
"url": "https://github.com/angular/angular/blob/main/adev/src/content/guide/directives/directive-composition-api.md"
} |
angular/adev/src/content/guide/directives/BUILD.bazel_0_1513 | load("//adev/shared-docs:index.bzl", "generate_guides")
generate_guides(
name = "directives",
srcs = glob([
"*.md",
]),
data = [
"//adev/src/assets/images:directives.svg",
"//adev/src/content/examples/attribute-directives:src/app/app.component.1.html",
"//adev/src/conten... | {
"end_byte": 1513,
"start_byte": 0,
"url": "https://github.com/angular/angular/blob/main/adev/src/content/guide/directives/BUILD.bazel"
} |
angular/adev/src/content/guide/directives/structural-directives.md_0_7819 | # 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... | {
"end_byte": 7819,
"start_byte": 0,
"url": "https://github.com/angular/angular/blob/main/adev/src/content/guide/directives/structural-directives.md"
} |
angular/adev/src/content/guide/directives/structural-directives.md_7819_11474 | ## Improving template type checking for custom directives
You can improve template type checking for custom directives by adding template guards to your directive definition.
These guards help the Angular template type checker find mistakes in the template at compile time, which can avoid runtime errors.
Two different... | {
"end_byte": 11474,
"start_byte": 7819,
"url": "https://github.com/angular/angular/blob/main/adev/src/content/guide/directives/structural-directives.md"
} |
angular/adev/src/content/guide/ngmodules/singleton-services.md_0_8368 | # 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 ... | {
"end_byte": 8368,
"start_byte": 0,
"url": "https://github.com/angular/angular/blob/main/adev/src/content/guide/ngmodules/singleton-services.md"
} |
angular/adev/src/content/guide/ngmodules/lazy-loading.md_0_1562 | # Lazy-loading feature modules
By default, NgModules are eagerly loaded. This means that as soon as the application loads, so do all the NgModules, whether they are immediately necessary or not.
For large applications with lots of routes, consider lazy loading —a design pattern that loads NgModules as needed.
Lazy loa... | {
"end_byte": 1562,
"start_byte": 0,
"url": "https://github.com/angular/angular/blob/main/adev/src/content/guide/ngmodules/lazy-loading.md"
} |
angular/adev/src/content/guide/ngmodules/lazy-loading.md_1562_9982 | 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... | {
"end_byte": 9982,
"start_byte": 1562,
"url": "https://github.com/angular/angular/blob/main/adev/src/content/guide/ngmodules/lazy-loading.md"
} |
angular/adev/src/content/guide/ngmodules/lazy-loading.md_9982_17247 | # 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... | {
"end_byte": 17247,
"start_byte": 9982,
"url": "https://github.com/angular/angular/blob/main/adev/src/content/guide/ngmodules/lazy-loading.md"
} |
angular/adev/src/content/guide/ngmodules/vs-jsmodule.md_0_5009 | # JavaScript modules vs. NgModules
JavaScript modules and NgModules can help you modularize your code, but they are very different.
Angular applications rely on both kinds of modules.
## JavaScript modules: Files exposing code
A [JavaScript module](https://javascript.info/modules "JavaScript.Info - Modules") is an i... | {
"end_byte": 5009,
"start_byte": 0,
"url": "https://github.com/angular/angular/blob/main/adev/src/content/guide/ngmodules/vs-jsmodule.md"
} |
angular/adev/src/content/guide/ngmodules/overview.md_0_3537 | # 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... | {
"end_byte": 3537,
"start_byte": 0,
"url": "https://github.com/angular/angular/blob/main/adev/src/content/guide/ngmodules/overview.md"
} |
angular/adev/src/content/guide/ngmodules/providers.md_0_6962 | # 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... | {
"end_byte": 6962,
"start_byte": 0,
"url": "https://github.com/angular/angular/blob/main/adev/src/content/guide/ngmodules/providers.md"
} |
angular/adev/src/content/guide/ngmodules/api.md_0_7768 | # 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... | {
"end_byte": 7768,
"start_byte": 0,
"url": "https://github.com/angular/angular/blob/main/adev/src/content/guide/ngmodules/api.md"
} |
angular/adev/src/content/guide/ngmodules/bootstrapping.md_0_6601 | # 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 ... | {
"end_byte": 6601,
"start_byte": 0,
"url": "https://github.com/angular/angular/blob/main/adev/src/content/guide/ngmodules/bootstrapping.md"
} |
angular/adev/src/content/guide/ngmodules/faq.md_0_7754 | # 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) ... | {
"end_byte": 7754,
"start_byte": 0,
"url": "https://github.com/angular/angular/blob/main/adev/src/content/guide/ngmodules/faq.md"
} |
angular/adev/src/content/guide/ngmodules/faq.md_7754_16931 | 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... | {
"end_byte": 16931,
"start_byte": 7754,
"url": "https://github.com/angular/angular/blob/main/adev/src/content/guide/ngmodules/faq.md"
} |
angular/adev/src/content/guide/ngmodules/faq.md_16931_25341 | 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 `Us... | {
"end_byte": 25341,
"start_byte": 16931,
"url": "https://github.com/angular/angular/blob/main/adev/src/content/guide/ngmodules/faq.md"
} |
angular/adev/src/content/guide/ngmodules/module-types.md_0_7172 | # 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 ... | {
"end_byte": 7172,
"start_byte": 0,
"url": "https://github.com/angular/angular/blob/main/adev/src/content/guide/ngmodules/module-types.md"
} |
angular/adev/src/content/guide/ngmodules/frequent.md_0_2816 | # 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... | {
"end_byte": 2816,
"start_byte": 0,
"url": "https://github.com/angular/angular/blob/main/adev/src/content/guide/ngmodules/frequent.md"
} |
angular/adev/src/content/guide/ngmodules/feature-modules.md_0_6824 | # 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... | {
"end_byte": 6824,
"start_byte": 0,
"url": "https://github.com/angular/angular/blob/main/adev/src/content/guide/ngmodules/feature-modules.md"
} |
angular/adev/src/content/guide/ngmodules/BUILD.bazel_0_207 | load("//adev/shared-docs:index.bzl", "generate_guides")
generate_guides(
name = "ngmodules",
srcs = glob([
"*.md",
]),
data = [
],
visibility = ["//adev:__subpackages__"],
)
| {
"end_byte": 207,
"start_byte": 0,
"url": "https://github.com/angular/angular/blob/main/adev/src/content/guide/ngmodules/BUILD.bazel"
} |
angular/adev/src/content/guide/ngmodules/sharing.md_0_2012 | # 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... | {
"end_byte": 2012,
"start_byte": 0,
"url": "https://github.com/angular/angular/blob/main/adev/src/content/guide/ngmodules/sharing.md"
} |
angular/adev/src/content/guide/di/overview.md_0_2493 | <docs-decorative-header title="Dependency injection in Angular" imgSrc="adev/src/assets/images/dependency_injection.svg"> <!-- markdownlint-disable-line -->
"DI" is a design pattern and mechanism for creating and delivering some parts of an app to other parts of an app that require them.
</docs-decorative-header>
Tip:... | {
"end_byte": 2493,
"start_byte": 0,
"url": "https://github.com/angular/angular/blob/main/adev/src/content/guide/di/overview.md"
} |
angular/adev/src/content/guide/di/creating-injectable-service.md_0_5554 | # 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... | {
"end_byte": 5554,
"start_byte": 0,
"url": "https://github.com/angular/angular/blob/main/adev/src/content/guide/di/creating-injectable-service.md"
} |
angular/adev/src/content/guide/di/dependency-injection-providers.md_0_9565 | # 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... | {
"end_byte": 9565,
"start_byte": 0,
"url": "https://github.com/angular/angular/blob/main/adev/src/content/guide/di/dependency-injection-providers.md"
} |
angular/adev/src/content/guide/di/di-in-action.md_0_3131 | # DI in action
This guide explores additional features of dependency injection in Angular.
## Custom providers with `@Inject`
Using a custom provider allows you to provide a concrete implementation for implicit dependencies, such as built-in browser APIs.
The following example uses an `InjectionToken` to provide the... | {
"end_byte": 3131,
"start_byte": 0,
"url": "https://github.com/angular/angular/blob/main/adev/src/content/guide/di/di-in-action.md"
} |
angular/adev/src/content/guide/di/dependency-injection.md_0_6519 | # 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 ... | {
"end_byte": 6519,
"start_byte": 0,
"url": "https://github.com/angular/angular/blob/main/adev/src/content/guide/di/dependency-injection.md"
} |
angular/adev/src/content/guide/di/dependency-injection-context.md_0_3004 | # 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... | {
"end_byte": 3004,
"start_byte": 0,
"url": "https://github.com/angular/angular/blob/main/adev/src/content/guide/di/dependency-injection-context.md"
} |
angular/adev/src/content/guide/di/hierarchical-dependency-injection.md_0_8882 | # 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... | {
"end_byte": 8882,
"start_byte": 0,
"url": "https://github.com/angular/angular/blob/main/adev/src/content/guide/di/hierarchical-dependency-injection.md"
} |
angular/adev/src/content/guide/di/hierarchical-dependency-injection.md_8882_16119 | Resolution rules
When resolving a token for a component/directive, Angular resolves it in two phases:
1. Against its parents in the `ElementInjector` hierarchy.
2. Against its parents in the `EnvironmentInjector` hierarchy.
When a component declares a dependency, Angular tries to satisfy that dependency with its ow... | {
"end_byte": 16119,
"start_byte": 8882,
"url": "https://github.com/angular/angular/blob/main/adev/src/content/guide/di/hierarchical-dependency-injection.md"
} |
angular/adev/src/content/guide/di/hierarchical-dependency-injection.md_16119_17607 | structure of the template
When you provide services in the component class, services are visible within the `ElementInjector` tree relative to where and how you provide those services.
Understanding the underlying logical structure of the Angular template will give you a foundation for configuring services and in tur... | {
"end_byte": 17607,
"start_byte": 16119,
"url": "https://github.com/angular/angular/blob/main/adev/src/content/guide/di/hierarchical-dependency-injection.md"
} |
angular/adev/src/content/guide/di/hierarchical-dependency-injection.md_17607_25301 | viding services in `@Component()`
How you provide services using a `@Component()` (or `@Directive()`) decorator determines their visibility.
The following sections demonstrate `providers` and `viewProviders` along with ways to modify service visibility with `@SkipSelf()` and `@Host()`.
A component class can provide s... | {
"end_byte": 25301,
"start_byte": 17607,
"url": "https://github.com/angular/angular/blob/main/adev/src/content/guide/di/hierarchical-dependency-injection.md"
} |
angular/adev/src/content/guide/di/hierarchical-dependency-injection.md_25301_28944 | oviders` array
Use the `viewProviders` array as another way to provide services in the `@Component()` decorator.
Using `viewProviders` makes services visible in the `<#VIEW>`.
HELPFUL: The steps are the same as using the `providers` array, with the exception of using the `viewProviders` array instead.
For step-by-st... | {
"end_byte": 28944,
"start_byte": 25301,
"url": "https://github.com/angular/angular/blob/main/adev/src/content/guide/di/hierarchical-dependency-injection.md"
} |
angular/adev/src/content/guide/di/hierarchical-dependency-injection.md_28944_35856 | ders`
The `viewProviders` field is conceptually similar to `providers`, but there is one notable difference.
Configured providers in `viewProviders` are not visible to projected content that ends up as a logical children of the component.
To see the difference between using `providers` and `viewProviders`, add anothe... | {
"end_byte": 35856,
"start_byte": 28944,
"url": "https://github.com/angular/angular/blob/main/adev/src/content/guide/di/hierarchical-dependency-injection.md"
} |
angular/adev/src/content/guide/di/hierarchical-dependency-injection.md_35856_40775 | viders`
Remember, `<app-child>` provides the `AnimalService` in the `viewProviders` array with the value of dog <code>🐶</code>.
Because the injector has only to look at the `ElementInjector` of the `<app-child>` for the `AnimalService`, it never sees the whale <code>🐳</code>.
As in the `FlowerService`... | {
"end_byte": 40775,
"start_byte": 35856,
"url": "https://github.com/angular/angular/blob/main/adev/src/content/guide/di/hierarchical-dependency-injection.md"
} |
angular/adev/src/content/guide/di/hierarchical-dependency-injection.md_40775_49721 | 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... | {
"end_byte": 49721,
"start_byte": 40775,
"url": "https://github.com/angular/angular/blob/main/adev/src/content/guide/di/hierarchical-dependency-injection.md"
} |
angular/adev/src/content/guide/di/hierarchical-dependency-injection.md_49721_49870 | cs-pill-row>
<docs-pill href="/guide/di/dependency-injection-providers" title="DI Providers"/>
</docs-pill-row> | {
"end_byte": 49870,
"start_byte": 49721,
"url": "https://github.com/angular/angular/blob/main/adev/src/content/guide/di/hierarchical-dependency-injection.md"
} |
angular/adev/src/content/guide/di/BUILD.bazel_0_379 | load("//adev/shared-docs:index.bzl", "generate_guides")
generate_guides(
name = "di",
srcs = glob([
"*.md",
]),
data = [
"//adev/src/assets/images:dependency_injection.svg",
"//adev/src/content/examples/resolution-modifiers:src/app/self/self.component.ts",
],
mermaid_blo... | {
"end_byte": 379,
"start_byte": 0,
"url": "https://github.com/angular/angular/blob/main/adev/src/content/guide/di/BUILD.bazel"
} |
angular/adev/src/content/guide/di/lightweight-injection-tokens.md_0_9579 | # Optimizing client application size with lightweight injection tokens
This page provides a conceptual overview of a dependency injection technique that is recommended for library developers.
Designing your library with *lightweight injection tokens* helps optimize the bundle size of client applications that use your ... | {
"end_byte": 9579,
"start_byte": 0,
"url": "https://github.com/angular/angular/blob/main/adev/src/content/guide/di/lightweight-injection-tokens.md"
} |
angular/adev/src/content/guide/forms/overview.md_0_6241 | <docs-decorative-header title="Forms in Angular" imgSrc="adev/src/assets/images/overview.svg"> <!-- markdownlint-disable-line -->
Handling user input with forms is the cornerstone of many common applications.
</docs-decorative-header>
Applications use forms to enable users to log in, to update a profile, to enter sens... | {
"end_byte": 6241,
"start_byte": 0,
"url": "https://github.com/angular/angular/blob/main/adev/src/content/guide/forms/overview.md"
} |
angular/adev/src/content/guide/forms/overview.md_6241_14515 | ## 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... | {
"end_byte": 14515,
"start_byte": 6241,
"url": "https://github.com/angular/angular/blob/main/adev/src/content/guide/forms/overview.md"
} |
angular/adev/src/content/guide/forms/overview.md_14515_19165 | ## Testing
Testing plays a large part in complex applications.
A simpler testing strategy is useful when validating that your forms function correctly.
Reactive forms and template-driven forms have different levels of reliance on rendering the UI to perform assertions based on form control and form field changes.
The ... | {
"end_byte": 19165,
"start_byte": 14515,
"url": "https://github.com/angular/angular/blob/main/adev/src/content/guide/forms/overview.md"
} |
angular/adev/src/content/guide/forms/dynamic-forms.md_0_8848 | # Building dynamic forms
Many forms, such as questionnaires, can be very similar to one another in format and intent.
To make it faster and easier to generate different versions of such a form, you can create a _dynamic form template_ based on metadata that describes the business object model.
Then, use the template t... | {
"end_byte": 8848,
"start_byte": 0,
"url": "https://github.com/angular/angular/blob/main/adev/src/content/guide/forms/dynamic-forms.md"
} |
angular/adev/src/content/guide/forms/form-validation.md_0_9567 | # Validating form input
You can improve overall data quality by validating user input for accuracy and completeness.
This page shows how to validate user input from the UI and display useful validation messages, in both reactive and template-driven forms.
## Validating input in template-driven forms
To add validatio... | {
"end_byte": 9567,
"start_byte": 0,
"url": "https://github.com/angular/angular/blob/main/adev/src/content/guide/forms/form-validation.md"
} |
angular/adev/src/content/guide/forms/form-validation.md_9567_14726 | ol status CSS classes
Angular automatically mirrors many control properties onto the form control element as CSS classes.
Use these classes to style form control elements according to the state of the form.
The following classes are currently supported.
* `.ng-valid`
* `.ng-invalid`
* `.ng-pending`
* `.ng-pristine`
*... | {
"end_byte": 14726,
"start_byte": 9567,
"url": "https://github.com/angular/angular/blob/main/adev/src/content/guide/forms/form-validation.md"
} |
angular/adev/src/content/guide/forms/form-validation.md_14726_21860 | 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,... | {
"end_byte": 21860,
"start_byte": 14726,
"url": "https://github.com/angular/angular/blob/main/adev/src/content/guide/forms/form-validation.md"
} |
angular/adev/src/content/guide/forms/reactive-forms.md_0_7330 | # Reactive forms
Reactive forms provide a model-driven approach to handling form inputs whose values change over time.
This guide shows you how to create and update a basic form control, progress to using multiple controls in a group, validate form values, and create dynamic forms where you can add or remove controls ... | {
"end_byte": 7330,
"start_byte": 0,
"url": "https://github.com/angular/angular/blob/main/adev/src/content/guide/forms/reactive-forms.md"
} |
angular/adev/src/content/guide/forms/reactive-forms.md_7330_16022 | ## Grouping form controls
Forms typically contain several related controls.
Reactive forms provide two ways of grouping multiple related controls into a single input form.
| Form groups | Details |
|:--- |:--- |
| Form group | Defines a form with a fixed set of controls that you can manage together. Form... | {
"end_byte": 16022,
"start_byte": 7330,
"url": "https://github.com/angular/angular/blob/main/adev/src/content/guide/forms/reactive-forms.md"
} |
angular/adev/src/content/guide/forms/reactive-forms.md_16022_23456 | ### 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... | {
"end_byte": 23456,
"start_byte": 16022,
"url": "https://github.com/angular/angular/blob/main/adev/src/content/guide/forms/reactive-forms.md"
} |
angular/adev/src/content/guide/forms/reactive-forms.md_23456_30706 | ## 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... | {
"end_byte": 30706,
"start_byte": 23456,
"url": "https://github.com/angular/angular/blob/main/adev/src/content/guide/forms/reactive-forms.md"
} |
angular/adev/src/content/guide/forms/template-driven-forms.md_0_7595 | # 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... | {
"end_byte": 7595,
"start_byte": 0,
"url": "https://github.com/angular/angular/blob/main/adev/src/content/guide/forms/template-driven-forms.md"
} |
angular/adev/src/content/guide/forms/template-driven-forms.md_7595_11898 | 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 de... | {
"end_byte": 11898,
"start_byte": 7595,
"url": "https://github.com/angular/angular/blob/main/adev/src/content/guide/forms/template-driven-forms.md"
} |
angular/adev/src/content/guide/forms/template-driven-forms.md_11898_19564 | 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 ... | {
"end_byte": 19564,
"start_byte": 11898,
"url": "https://github.com/angular/angular/blob/main/adev/src/content/guide/forms/template-driven-forms.md"
} |
angular/adev/src/content/guide/forms/template-driven-forms.md_19564_24951 | Submit the form with `ngSubmit`
The user should be able to submit this form after filling it in.
The **Submit** button at the bottom of the form does nothing on its own, but it does trigger a form-submit event because of its type (`type="submit"`).
To respond to this event, take the following steps.
<docs-workflow>... | {
"end_byte": 24951,
"start_byte": 19564,
"url": "https://github.com/angular/angular/blob/main/adev/src/content/guide/forms/template-driven-forms.md"
} |
angular/adev/src/content/guide/forms/BUILD.bazel_0_3972 | load("//adev/shared-docs:index.bzl", "generate_guides")
generate_guides(
name = "forms",
srcs = glob([
"*.md",
]),
data = [
"//adev/src/assets/images:overview.svg",
"//adev/src/content/examples/dynamic-form:src/app/app.component.ts",
"//adev/src/content/examples/dynamic-... | {
"end_byte": 3972,
"start_byte": 0,
"url": "https://github.com/angular/angular/blob/main/adev/src/content/guide/forms/BUILD.bazel"
} |
angular/adev/src/content/guide/forms/typed-forms.md_0_7413 | # 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" />... | {
"end_byte": 7413,
"start_byte": 0,
"url": "https://github.com/angular/angular/blob/main/adev/src/content/guide/forms/typed-forms.md"
} |
angular/adev/src/content/guide/signals/rxjs-interop.md_0_5505 | # 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... | {
"end_byte": 5505,
"start_byte": 0,
"url": "https://github.com/angular/angular/blob/main/adev/src/content/guide/signals/rxjs-interop.md"
} |
angular/adev/src/content/guide/signals/queries.md_0_8627 | # Signal queries
A component or directive can define queries that find child elements and read values from their injectors.
Developers most commonly use queries to retrieve references to components, directives, DOM elements, and more.
There are two categories of query: view queries and content queries.
Signal queri... | {
"end_byte": 8627,
"start_byte": 0,
"url": "https://github.com/angular/angular/blob/main/adev/src/content/guide/signals/queries.md"
} |
angular/adev/src/content/guide/signals/overview.md_0_7975 | <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>
... | {
"end_byte": 7975,
"start_byte": 0,
"url": "https://github.com/angular/angular/blob/main/adev/src/content/guide/signals/overview.md"
} |
angular/adev/src/content/guide/signals/overview.md_7975_10656 | ## 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... | {
"end_byte": 10656,
"start_byte": 7975,
"url": "https://github.com/angular/angular/blob/main/adev/src/content/guide/signals/overview.md"
} |
angular/adev/src/content/guide/signals/model.md_0_4786 | # Model inputs
**Model inputs** are a special type of input that enable a component to propagate new values
back to another component.
When creating a component, you can define a model input similarly to how you create a standard
input.
```angular-ts
import {Component, model, input} from '@angular/core';
@Component... | {
"end_byte": 4786,
"start_byte": 0,
"url": "https://github.com/angular/angular/blob/main/adev/src/content/guide/signals/model.md"
} |
angular/adev/src/content/guide/signals/inputs.md_0_5109 | # 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... | {
"end_byte": 5109,
"start_byte": 0,
"url": "https://github.com/angular/angular/blob/main/adev/src/content/guide/signals/inputs.md"
} |
angular/adev/src/content/guide/signals/BUILD.bazel_0_253 | load("//adev/shared-docs:index.bzl", "generate_guides")
generate_guides(
name = "signals",
srcs = glob([
"*.md",
]),
data = [
"//adev/src/assets/images:signals.svg",
],
visibility = ["//adev:__subpackages__"],
)
| {
"end_byte": 253,
"start_byte": 0,
"url": "https://github.com/angular/angular/blob/main/adev/src/content/guide/signals/BUILD.bazel"
} |
angular/adev/src/content/guide/pipes/template.md_0_2152 | # Using a pipe in a template
To apply a pipe, use the pipe operator (`|`) within a template expression as shown in the following code example.
<docs-code language="angular-html" header="app.component.html">
<p>The hero's birthday is {{ birthday | date }}</p>
</docs-code>
The component's `birthday` value flows throug... | {
"end_byte": 2152,
"start_byte": 0,
"url": "https://github.com/angular/angular/blob/main/adev/src/content/guide/pipes/template.md"
} |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.