id
stringlengths
6
6
text
stringlengths
20
17.2k
title
stringclasses
1 value
004691
# 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...
004693
# 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...
004697
# 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:...
004699
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...
004711
# Communicating with the Service Worker Enabling service worker support does more than just register the service worker; it also provides services you can use to interact with the service worker and control the caching of your application. ## `SwUpdate` service The `SwUpdate` service gives you access to events that ...
004727
# Creating libraries This page provides a conceptual overview of how to create and publish new libraries to extend Angular functionality. If you find that you need to solve the same problem in more than one application \(or want to share your solution with other developers\), you have a candidate for a library. A sim...
004728
anaging assets in a library In your Angular library, the distributable can include additional assets like theming files, Sass mixins, or documentation \(like a changelog\). For more information [copy assets into your library as part of the build](https://github.com/ng-packagr/ng-packagr/blob/master/docs/copy-assets.md...
004731
# Configuring application environments You can define different named build configurations for your project, such as `development` and `staging`, with different defaults. Each named configuration can have defaults for any of the options that apply to the various builder targets, such as `build`, `serve`, and `test`. ...
004732
# The Angular CLI The Angular CLI is a command-line interface tool which allows you to scaffold, develop, test, deploy, and maintain Angular applications directly from a command shell. Angular CLI is published on npm as the `@angular/cli` package and includes a binary named `ng`. Commands invoking `ng` are using the ...
004735
## Define a generation rule You now have the framework in place for creating the code that actually modifies the user's application to set it up for the service defined in your library. The Angular workspace where the user installed your library contains multiple projects \(applications and libraries\). The user can ...
004737
# Generating code using schematics A schematic is a template-based code generator that supports complex logic. It is a set of instructions for transforming a software project by generating or modifying code. Schematics are packaged into collections and installed with npm. The schematic collection can be a powerful to...
004740
## Inputs and type-checking The template type checker checks whether a binding expression's type is compatible with that of the corresponding directive input. As an example, consider the following component: <docs-code language="typescript"> export interface User { name: string; } @Component({ selector: 'user-d...
004745
# Deployment When you are ready to deploy your Angular application to a remote server, you have various options. ## Automatic deployment with the CLI The Angular CLI command `ng deploy` executes the `deploy` [CLI builder](tools/cli/cli-builder) associated with your project. A number of third-party builders implement...
004746
# Migrating to the new build system In v17 and higher, the new build system provides an improved way to build Angular applications. This new build system includes: - A modern output format using ESM, with dynamic import expressions to support lazy module loading. - Faster build-time performance for both initial build...
004747
## Executing a build Once you have updated the application configuration, builds can be performed using `ng build` as was previously done. Depending on the choice of builder migration, some of the command line options may be different. If the build command is contained in any `npm` or other scripts, ensure they are re...
004748
# Building Angular apps You can build your Angular CLI application or library with the `ng build` command. This will compile your TypeScript code to JavaScript, as well as optimize, bundle, and minify the output as appropriate. `ng build` only executes the builder for the `build` target in the default project as spec...
004751
## Builder input You can invoke a builder indirectly through a CLI command such as `ng build`, or directly with the Angular CLI `ng run` command. In either case, you must provide required inputs, but can let other inputs default to values that are pre-configured for a specific *target*, specified by a [configuration](...
004752
and run Architect runs builders asynchronously. To invoke a builder, you schedule a task to be run when all configuration resolution is complete. The builder function is not executed until the scheduler returns a `BuilderRun` control object. The CLI typically schedules tasks by calling the `context.scheduleTarget()` ...
004764
<docs-decorative-header title="Rendering Dynamic Templates" imgSrc="adev/src/assets/images/templates.svg"> <!-- markdownlint-disable-line --> Use Angular's template syntax to create dynamic HTML. </docs-decorative-header> What you've learned so far enables you to break an application up into components of HTML, but th...
004765
<docs-decorative-header title="Conditionals and Loops" imgSrc="adev/src/assets/images/directives.svg"> <!-- markdownlint-disable-line --> Conditionally show and/or repeat content based on dynamic data. </docs-decorative-header> One of the advantages of using a framework like Angular is that it provides built-in soluti...
004766
<docs-decorative-header title="Components" imgSrc="adev/src/assets/images/components.svg"> <!-- markdownlint-disable-line --> The fundamental building block for creating applications in Angular. </docs-decorative-header> Components provide structure for organizing your project into easy-to-understand parts with clear ...
004807
/** * @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 */ /* tslint:disable:no-console */ // #docregion Component import {Component} from '@angular/core'; import {FormArray,...
004813
/** * @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 */ // #docregion Component import {Component} from '@angular/core'; @Component({ selector: 'example-app', template...
004825
/** * @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 */ /* tslint:disable:no-console */ // #docregion Component import {Component} from '@angular/core'; import {NgForm} fr...
004834
/** * @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 { inject, InjectFlags, InjectionToken, InjectOptions, Injector, ProviderToken, ɵsetCurrentInjec...
004870
/** * @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 { AfterContentChecked, AfterContentInit, AfterViewChecked, AfterViewInit, Component, DoCheck, I...
004878
/** * @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 { Component, Injectable, Injector, Input, NgModule, OnInit, TemplateRef, ViewChild, ViewCon...
004915
/** * @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 {Component, inject, Injectable} from '@angular/core'; import {bootstrapApplication} from '@angular/platform-b...
004917
/** * @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 */ // #docregion activated-route import {Component, NgModule} from '@angular/core'; // #enddocregion activated-route imp...
004922
# CLI Overview and Command Reference The Angular CLI is a command-line interface tool that you use to initialize, develop, scaffold, and maintain Angular applications directly from a command shell. ## Installing Angular CLI Major versions of Angular CLI follow the supported major version of Angular, but minor versio...
004949
// #docregion import {CommonModule} from '@angular/common'; import {NgModule} from '@angular/core'; import {FormsModule} from '@angular/forms'; import {BrowserModule} from '@angular/platform-browser'; import {AppComponent} from './app.component'; import {ActorFormComponent} from './actor-form/actor-form.component'; @...
004950
// #docregion import {Component} from '@angular/core'; @Component({ selector: 'app-root', templateUrl: './app.component.html', standalone: false, }) export class AppComponent {}
004962
import {Injectable} from '@angular/core'; @Injectable({ providedIn: 'root', }) export class MyLibService {}
005027
<!DOCTYPE html> <html lang="en"> <head> <title>Angular Quickstart Seed</title> <base href="/"> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1"> <link rel="stylesheet" href="styles.css"> <!-- Polyfills --> <script src="node_modules/core-js/client/...
005044
import {NgModule} from '@angular/core'; import {CommonModule} from '@angular/common'; import {FormsModule} from '@angular/forms'; import {FavoriteColorComponent} from './favorite-color/favorite-color.component'; @NgModule({ imports: [CommonModule, FormsModule], declarations: [FavoriteColorComponent], exports: [F...
005051
import {bootstrapApplication, provideProtractorTestingSupport} from '@angular/platform-browser'; import {provideHttpClient} from '@angular/common/http'; import {AppComponent} from './app/app.component'; bootstrapApplication(AppComponent, { // HttpClientModule is only used in deprecated HeroListComponent providers...
005085
import {provideHttpClient} from '@angular/common/http'; import {ApplicationConfig, importProvidersFrom} from '@angular/core'; import {provideProtractorTestingSupport} from '@angular/platform-browser'; import {provideRouter} from '@angular/router'; import {HttpClientInMemoryWebApiModule} from 'angular-in-memory-web-api'...
005088
/* eslint-disable @angular-eslint/directive-selector, guard-for-in, @angular-eslint/no-input-rename */ import { Component, ContentChildren, Directive, EventEmitter, HostBinding, HostListener, Injectable, Input, OnChanges, OnDestroy, OnInit, Optional, Output, Pipe, PipeTransform, SimpleC...
005089
@Component({ standalone: true, selector: 'my-if-child-1', template: ` <h4>MyIfChildComp</h4> <div> <label for="child-value" >Child value: <input id="child-value" [(ngModel)]="childValue" /> </label> </div> <p><i>Change log:</i></p> @for (log of changeLog; track log; let i = $in...
005106
// #docplaster import {ComponentFixture, inject, TestBed} from '@angular/core/testing'; import {UserService} from '../model/user.service'; import {WelcomeComponent} from './welcome.component'; // #docregion mock-user-service class MockUserService { isLoggedIn = true; user = {name: 'Test User'}; } // #enddocregion...
005109
import {provideHttpClient} from '@angular/common/http'; import {HttpTestingController, provideHttpClientTesting} from '@angular/common/http/testing'; import {NO_ERRORS_SCHEMA} from '@angular/core'; import {TestBed, waitForAsync} from '@angular/core/testing'; import {By} from '@angular/platform-browser'; import {Navigat...
005117
// #docplaster import {fakeAsync, ComponentFixture, TestBed, tick, waitForAsync} from '@angular/core/testing'; import {asyncData, asyncError} from '../../testing'; import {Subject, defer, of, throwError} from 'rxjs'; import {last} from 'rxjs/operators'; import {TwainComponent} from './twain.component'; import {Twain...
005124
import {Injectable, signal} from '@angular/core'; @Injectable({providedIn: 'root'}) export class UserService { isLoggedIn = signal(true); user = signal({name: 'Sam Spade'}); }
005137
// #docplaster import {HttpClient, HttpHandler, provideHttpClient} from '@angular/common/http'; import {HttpTestingController, provideHttpClientTesting} from '@angular/common/http/testing'; import {fakeAsync, TestBed, tick} from '@angular/core/testing'; import {provideRouter, Router} from '@angular/router'; import {Rou...
005157
// #docplaster import {APP_BASE_HREF} from '@angular/common'; import {CommonEngine} from '@angular/ssr/node'; import express from 'express'; import {fileURLToPath} from 'node:url'; import {dirname, join, resolve} from 'node:path'; import bootstrap from './src/main.server'; // The Express app is exported so that it ca...
005168
import {mergeApplicationConfig, ApplicationConfig} from '@angular/core'; import {provideServerRendering} from '@angular/platform-server'; import {appConfig} from './app.config'; const serverConfig: ApplicationConfig = { providers: [provideServerRendering()], }; export const config = mergeApplicationConfig(appConfig...
005171
import {Component} from '@angular/core'; import {RouterLink, RouterOutlet} from '@angular/router'; import {PLATFORM_ID, APP_ID, Inject} from '@angular/core'; import {isPlatformBrowser} from '@angular/common'; import {MessagesComponent} from './messages/messages.component'; @Component({ standalone: true, selector...
005180
import {Component, OnInit} from '@angular/core'; import {NgFor} from '@angular/common'; import {RouterLink} from '@angular/router'; import {Hero} from '../hero'; import {HeroService} from '../hero.service'; @Component({ standalone: true, selector: 'app-heroes', templateUrl: './heroes.component.html', imports:...
005192
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <base href="/"> <title>Elements</title> <meta name="viewport" content="width=device-width, initial-scale=1"> </head> <body> <app-root></app-root> </body> </html>
005209
<ul> <li *ngFor="let hero of heroes"> {{ hero.name }} </li> </ul>
005223
// #docregion import {Component} from '@angular/core'; // #docregion example /* avoid */ // UsersComponent is in an Admin feature @Component({ standalone: true, selector: 'users', template: '', }) export class UsersComponent {} // #enddocregion example
005224
// #docplaster // #docregion import {Component} from '@angular/core'; // #docregion example @Component({ // #enddocregion example template: '<div>users component</div>', // #docregion example standalone: true, selector: 'admin-users', }) export class UsersComponent {} // #enddocregion example
005294
import {Component} from '@angular/core'; import {HeroesComponent} from './heroes'; @Component({ standalone: true, selector: 'sg-app', template: '<toh-heroes></toh-heroes>', imports: [HeroesComponent], }) export class AppComponent {}
005297
<!-- #docregion --> <div> <h2>My Heroes</h2> <ul class="heroes"> @for (hero of heroes | async; track hero) { <li> <button type="button" (click)="selectedHero=hero"> <span class="badge">{{ hero.id }}</span> <span class="name">{{ hero.name }}</span> </button> </li> ...
005298
import {Component} from '@angular/core'; import {Observable} from 'rxjs'; import {Hero, HeroService} from './shared'; import {AsyncPipe, NgFor, NgIf, UpperCasePipe} from '@angular/common'; // #docregion example /* avoid */ @Component({ standalone: true, selector: 'toh-heroes', template: ` <div> <h2>M...
005366
// #docregion /* avoid */ import {Component, OnInit} from '@angular/core'; import {HttpClient} from '@angular/common/http'; import {Observable} from 'rxjs'; import {catchError, finalize} from 'rxjs/operators'; import {Hero} from '../shared/hero.model'; const heroesUrl = 'http://angular.io'; @Component({ standalo...
005368
// #docregion example import {Component, OnInit} from '@angular/core'; import {Hero, HeroService} from '../shared'; @Component({ standalone: true, selector: 'toh-hero-list', template: `...`, }) export class HeroListComponent implements OnInit { heroes: Hero[] = []; constructor(private heroService: HeroServi...
005373
// #docregion /* avoid */ import {Component, NgModule, OnInit} from '@angular/core'; import {BrowserModule} from '@angular/platform-browser'; import {platformBrowserDynamic} from '@angular/platform-browser-dynamic'; interface Hero { id: number; name: string; } @Component({ selector: 'app-root', template: ` ...
005403
<!-- #docplaster --> <!-- #docregion --> <h1>Structural Directives</h1> <p>Conditional display of hero</p> <blockquote> <!-- #docregion asterisk --> <div *ngIf="hero" class="name">{{hero.name}}</div> <!-- #enddocregion asterisk --> </blockquote> <p>List of heroes</p> <ul> <li *ngFor="let hero of heroes">{{hero.na...
005478
import {Component} from '@angular/core'; import {ChildComponent} from './child.component'; @Component({ standalone: true, selector: 'app-parent', imports: [ChildComponent], template: '<app-child/>', }) export class ParentComponent {}
005510
<h1>Built-in Directives</h1> <h2>Built-in attribute directives</h2> <h3 id="ngModel">NgModel (two-way) Binding</h3> <fieldset><h4>NgModel examples</h4> <p>Current item name: {{ currentItem.name }}</p> <p> <label for="without">without NgModel:</label> <input [value]="currentItem.name" (input)="currentItem...
005511
<p>with trackBy and <em>semi-colon</em> separator</p> <div class="box"> <!-- #docregion trackBy --> <div *ngFor="let item of items; trackBy: trackByItems"> ({{ item.id }}) {{ item.name }} </div> <!-- #enddocregion trackBy --> </div> <p>with trackBy and <em>comma</em> separator</p> <div class="box"> <div ...
005523
// #docregion import {Component} from '@angular/core'; import {CarComponent} from './car/car.component'; import {HeroesComponent} from './heroes/heroes.component'; @Component({ standalone: true, selector: 'app-root', template: ` <h1>{{title}}</h1> <app-car></app-car> <app-heroes></app-heroes> `, ...
005527
import {Component, Inject} from '@angular/core'; import {APP_CONFIG, AppConfig} from './injection.config'; import {UserService} from './user.service'; import {HeroesComponent} from './heroes/heroes.component'; import {HeroesTspComponent} from './heroes/heroes-tsp.component'; import {ProvidersComponent} from './provide...
005530
import {ApplicationConfig} from '@angular/core'; import {Logger} from './logger.service'; import {UserService} from './user.service'; import {APP_CONFIG, HERO_DI_CONFIG} from './injection.config'; import {provideProtractorTestingSupport} from '@angular/platform-browser'; const appConfig: ApplicationConfig = { provid...
005531
import {Component, Inject} from '@angular/core'; import {APP_CONFIG, AppConfig} from './injection.config'; import {CarComponent} from './car/car.component'; import {HeroesComponent} from './heroes/heroes.component'; @Component({ standalone: true, selector: 'app-root', template: ` <h1>{{title}}</h1> <app...
005553
// #docregion import {EnvironmentInjector, inject, Injectable, runInInjectionContext} from '@angular/core'; @Injectable({providedIn: 'root'}) export class SomeService {} // #docregion run-in-context @Injectable({ providedIn: 'root', }) export class HeroService { private environmentInjector = inject(EnvironmentInj...
005556
import {NgModule} from '@angular/core'; import {BrowserModule} from '@angular/platform-browser'; import {RouterModule} from '@angular/router'; import {ServiceModule} from './service-and-module'; // #docregion @NgModule({ imports: [BrowserModule, RouterModule.forRoot([]), ServiceModule], }) export class AppModule {}
005558
import {Injectable} from '@angular/core'; // #docregion @Injectable({ providedIn: 'root', }) export class Service {}
005559
// #docregion import {Injectable, NgModule} from '@angular/core'; @Injectable() export class Service { doSomething(): void {} } @NgModule({ providers: [Service], }) export class ServiceModule {}
005572
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Animations</title> <base href="/"> <meta name="viewport" content="width=device-width, initial-scale=1"> </head> <body> <app-root></app-root> </body> </html>
005602
import {ApplicationConfig} from '@angular/core'; import {routes} from './app.routes'; import {provideRouter} from '@angular/router'; import {provideProtractorTestingSupport} from '@angular/platform-browser'; import {provideAnimations} from '@angular/platform-browser/animations'; export const appConfig: ApplicationConf...
005613
import {NgModule} from '@angular/core'; import {BrowserModule} from '@angular/platform-browser'; import {BrowserAnimationsModule} from '@angular/platform-browser/animations'; @NgModule({ imports: [BrowserModule, BrowserAnimationsModule], declarations: [], bootstrap: [], }) export class AppModule {}
005695
// #docplaster import {NgModule} from '@angular/core'; import {Routes, RouterModule} from '@angular/router'; // CLI imports router // #docregion child-routes const routes: Routes = [ { path: 'first-component', component: FirstComponent, // this is the component with the <router-outlet> in the template ch...
005702
// #docplaster // #docregion import {inject} from '@angular/core'; import {Router, NavigationExtras} from '@angular/router'; import {AuthService} from './auth.service'; export const authGuard = () => { const authService = inject(AuthService); const router = inject(Router); if (authService.isLoggedIn) { retu...
005705
// #docplaster import {inject} from '@angular/core'; import {Router, NavigationExtras} from '@angular/router'; import {AuthService} from './auth.service'; export const authGuard = () => { const router = inject(Router); const authService = inject(AuthService); if (authService.isLoggedIn) { return true; } ...
005708
// #docregion import {inject} from '@angular/core'; import {Router} from '@angular/router'; import {AuthService} from './auth.service'; export const authGuard = () => { const authService = inject(AuthService); const router = inject(Router); if (authService.isLoggedIn) { return true; } // Redirect to t...
005709
import {inject} from '@angular/core'; import {Router} from '@angular/router'; import {AuthService} from './auth.service'; export const authGuard = () => { const authService = inject(AuthService); const router = inject(Router); if (authService.isLoggedIn) { return true; } // Redirect to the login page ...
005783
import {Component} from '@angular/core'; import {FormsModule} from '@angular/forms'; import {bootstrapApplication} from '@angular/platform-browser'; @Component({ selector: 'app-root', standalone: true, template: ` <label for="name">Name:</label> <input type="text" id="name" [(ngModel)]="name" placeholder...
005798
# Create Home component This tutorial lesson demonstrates how to create a new [component](guide/components) for your Angular app. <docs-video src="https://www.youtube.com/embed/R0nRX8jD2D0?si=OMVaw71EIa44yIOJ"/> ## What you'll learn Your app has a new component: `HomeComponent`. ## Conceptual preview of Angular co...
005831
import {Component} from '@angular/core'; import {CommonModule} from '@angular/common'; @Component({ selector: 'app-home', standalone: true, imports: [CommonModule], template: ` <section> <form> <input type="text" placeholder="Filter by city" /> <button class="primary" type="button">Se...
005847
import {Component} from '@angular/core'; import {CommonModule} from '@angular/common'; @Component({ selector: 'app-housing-location', standalone: true, imports: [CommonModule], template: ` <p>housing-location works!</p> `, styleUrls: ['./housing-location.component.css'], }) export class HousingLocation...
005853
# Add a property binding to a component’s template This tutorial lesson demonstrates how to add property binding to a template and use it to pass dynamic data to components. <docs-video src="https://www.youtube.com/embed/eM3zi_n7lNs?si=AsiczpWnMz5HhJqB&amp;start=599"/> ## What you'll learn * Your app has data bindi...
005876
import {Component} from '@angular/core'; import {HomeComponent} from './home/home.component'; import {RouterLink, RouterOutlet} from '@angular/router'; @Component({ selector: 'app-root', standalone: true, imports: [HomeComponent, RouterLink, RouterOutlet], template: ` <main> <a [routerLink]="['/']"> ...
005896
import {Component} from '@angular/core'; import {HomeComponent} from './home/home.component'; import {RouterLink, RouterOutlet} from '@angular/router'; @Component({ selector: 'app-root', standalone: true, imports: [HomeComponent, RouterLink, RouterOutlet], template: ` <main> <a [routerLink]="['/']"> ...
005909
# Add routes to the application This tutorial lesson demonstrates how to add routes to your app. <docs-video src="https://www.youtube.com/embed/r5DEBMuStPw?si=H6Bx6nLJoMLaMxkx" /> IMPORTANT: We recommend using your local environment to learn routing. ## What you'll learn At the end of this lesson your application ...
005961
# Use *ngFor to list objects in component This tutorial lesson demonstrates how to use `ngFor` directive in Angular templates in order to display dynamically repeated data in a template. <docs-video src="https://www.youtube.com/embed/eM3zi_n7lNs?si=MIl5NcRxvcLjYt5f&amp;start=477"/> ## What you'll learn * You will h...
006004
# Add HTTP communication to your app This tutorial demonstrates how to integrate HTTP and an API into your app. Up until this point your app has read data from a static array in an Angular service. The next step is to use a JSON server that your app will communicate with over HTTP. The HTTP request will simulate the ...
006005
## What you'll learn Your app will use data from a JSON server <docs-workflow> <docs-step title="Configure the JSON server"> JSON Server is an open source tool used to create mock REST APIs. You'll use it to serve the housing location data that is currently stored in the housing service. 1. Install `json-server` fr...
006012
import {Component} from '@angular/core'; import {HomeComponent} from './home/home.component'; import {RouterLink, RouterOutlet} from '@angular/router'; @Component({ selector: 'app-root', standalone: true, imports: [HomeComponent, RouterLink, RouterOutlet], template: ` <main> <a [routerLink]="['/']"> ...
006026
/* * Protractor support is deprecated in Angular. * Protractor is used in this example for compatibility with Angular documentation tools. */ import {bootstrapApplication, provideProtractorTestingSupport} from '@angular/platform-browser'; import {AppComponent} from './app/app.component'; import {provideRouter} fro...
006031
import {Component} from '@angular/core'; import {HomeComponent} from './home/home.component'; import {RouterLink, RouterOutlet} from '@angular/router'; @Component({ selector: 'app-root', standalone: true, imports: [HomeComponent, RouterLink, RouterOutlet], template: ` <main> <a [routerLink]="['/']"> ...
006048
# Control Flow in Components - `@if` Deciding what to display on the screen for a user is a common task in application development. Many times, the decision is made programmatically using conditions. To express conditional displays in templates, Angular uses the `@if` template syntax. In this activity, you'll learn ...
006054
import {Component} from '@angular/core'; import {RouterOutlet, RouterLink} from '@angular/router'; @Component({ selector: 'app-root', template: ` <nav> <a routerLink="/">Home</a> | <a routerLink="/user">User</a> </nav> <router-outlet /> `, standalone: true, imports: [RouterOutle...
006064
# Routing Overview For most apps, there comes a point where the app requires more than a single page. When that time inevitably comes, routing becomes a big part of the performance story for users. In this activity, you'll learn how to setup and configure your app to use Angular Router. <hr> <docs-workflow> <docs-...
006066
import {Routes} from '@angular/router'; export const routes: Routes = [];
006086
# Inject-based dependency injection Creating an injectable service is the first part of the dependency injection (DI) system in Angular. How do you inject a service into a component? Angular has a convenient function called `inject()` that can be used in the proper context. Note: Injection contexts are beyond the sco...
006101
# Reactive Forms When you want to manage your forms programmatically instead of relying purely on the template, reactive forms are the answer. In this activity, you'll learn how to setup reactive forms. <hr> <docs-workflow> <docs-step title="Import `ReactiveForms` module"> In `app.component.ts`, import `ReactiveF...
006109
# Control Flow in Components - `@for` Often when building web applications, you need to repeat some code a specific number of times - for example, given an array of names, you may want to display each name in a `<p>` tag. In this activity, you'll learn how to use `@for` to repeat elements in a template. <hr/> The sy...
006144
# Property Binding in Angular Property binding in Angular enables you to set values for properties of HTML elements, Angular components and more. Use property binding to dynamically set values for properties and attributes. You can do things such as toggle button features, set image paths programmatically, and share ...