{"id":18850550,"url":"https://github.com/manthanank/learn-angular","last_synced_at":"2025-10-14T14:43:00.289Z","repository":{"id":65683327,"uuid":"587799765","full_name":"manthanank/learn-angular","owner":"manthanank","description":"Complete Guide to Learn Angular.","archived":false,"fork":false,"pushed_at":"2025-05-21T03:36:19.000Z","size":1928,"stargazers_count":66,"open_issues_count":0,"forks_count":18,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-10-03T15:56:24.594Z","etag":null,"topics":["angular","learn","learn-angular","learning-angular","rxjs"],"latest_commit_sha":null,"homepage":"","language":"HTML","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/manthanank.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":"SECURITY.md","support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null},"funding":{"github":["manthanank"],"open_collective":"manthanank","buy_me_a_coffee":"manthanank","patreon":"manthanank"}},"created_at":"2023-01-11T16:05:22.000Z","updated_at":"2025-09-15T07:02:07.000Z","dependencies_parsed_at":"2024-05-08T05:28:01.837Z","dependency_job_id":"463919f1-775b-476b-be1b-fecf88c28c04","html_url":"https://github.com/manthanank/learn-angular","commit_stats":null,"previous_names":[],"tags_count":63,"template":false,"template_full_name":null,"purl":"pkg:github/manthanank/learn-angular","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/manthanank%2Flearn-angular","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/manthanank%2Flearn-angular/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/manthanank%2Flearn-angular/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/manthanank%2Flearn-angular/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/manthanank","download_url":"https://codeload.github.com/manthanank/learn-angular/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/manthanank%2Flearn-angular/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":279019157,"owners_count":26086682,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-10-14T02:00:06.444Z","response_time":60,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["angular","learn","learn-angular","learning-angular","rxjs"],"created_at":"2024-11-08T03:29:52.687Z","updated_at":"2025-10-14T14:43:00.270Z","avatar_url":"https://github.com/manthanank.png","language":"HTML","funding_links":["https://github.com/sponsors/manthanank","https://opencollective.com/manthanank","https://buymeacoffee.com/manthanank","https://patreon.com/manthanank"],"categories":[],"sub_categories":[],"readme":"# Learn Angular\r\n\r\nThis repository contains a list of resources to learn Angular. It includes tutorials, articles, videos, books, and other resources to help you learn Angular from scratch.\r\n\r\n![npm](https://img.shields.io/npm/dw/learn-angular)\r\n![npm](https://img.shields.io/npm/dm/learn-angular)\r\n![npm](https://img.shields.io/npm/dy/learn-angular)\r\n![npm](https://img.shields.io/npm/dt/learn-angular)\r\n![GitHub issues](https://img.shields.io/github/issues/manthanank/learn-angular)\r\n![GitHub pull requests](https://img.shields.io/github/issues-pr/manthanank/learn-angular)\r\n![GitHub](https://img.shields.io/github/license/manthanank/learn-angular)\r\n![GitHub last commit](https://img.shields.io/github/last-commit/manthanank/learn-angular)\r\n![GitHub top language](https://img.shields.io/github/languages/top/manthanank/learn-angular)\r\n![GitHub repo size](https://img.shields.io/github/repo-size/manthanank/learn-angular)\r\n![GitHub code size in bytes](https://img.shields.io/github/languages/code-size/manthanank/learn-angular)\r\n![GitHub contributors](https://img.shields.io/github/contributors/manthanank/learn-angular)\r\n![GitHub forks](https://img.shields.io/github/forks/manthanank/learn-angular)\r\n![GitHub stars](https://img.shields.io/github/stars/manthanank/learn-angular)\r\n![GitHub watchers](https://img.shields.io/github/watchers/manthanank/learn-angular)\r\n\r\n## Table of Contents\r\n\r\n- [Introduction](#introduction)\r\n  - [Features of Angular](#features-of-angular)\r\n  - [Difference between AngularJS vs Angular](#difference-between-angularjs-vs-angular)\r\n  - [Angular vs React](#angular-vs-react)\r\n- [Roadmap](#roadmap)\r\n- [Configuration](#configuration)\r\n  - [Prerequisites](#prerequisites)\r\n  - [Installation](#installation)\r\n- [Components](#components)\r\n  - [Three main building blocks](#three-main-building-blocks)\r\n  - [Component Creation](#component-creation)\r\n    - [Using Angular CLI](#using-angular-cli)\r\n    - [Manual Creation](#manual-creation)\r\n    - [Example](#example)\r\n  - [Scope](#scope)\r\n  - [View Encapsulation](#view-encapsulation)\r\n    - [Emulated View Encapsulation](#emulated-view-encapsulation)\r\n    - [Shadow DOM View Encapsulation](#shadow-dom-view-encapsulation)\r\n    - [None View Encapsulation](#none-view-encapsulation)\r\n  - [Component Communication](#component-communication)\r\n    - [Parent to Child](#parent-to-child)\r\n    - [Child to Parent](#child-to-parent)\r\n- [Standalone Components](#standalone-components)\r\n- [Data Binding](#data-binding)\r\n  - [One Way Binding](#one-way-binding)\r\n  - [Two Way Binding](#two-ways-binding)\r\n- [Directives](#directives)\r\n  - [Structural Directives](#structural-directives)\r\n  - [Attribute Directives](#attribute-directives)\r\n  - [Custom Directives](#custom-directives)\r\n  - [Other Directives](#other-directives)\r\n- [New Control Flow](#new-control-flow)\r\n- [Pipes](#pipes)\r\n  - [Date Pipe](#date-pipe)\r\n  - [Uppercase Pipe](#uppercase-pipe)\r\n  - [Lowercase Pipe](#lowercase-pipe)\r\n  - [Currency Pipe](#currency-pipe)\r\n  - [Percent Pipe](#percent-pipe)\r\n  - [Slice Pipe](#slice-pipe)\r\n  - [Decimal/number Pipe](#decimalnumber-pipe)\r\n  - [JSON Pipe](#json-pipe)\r\n  - [Async Pipe](#async-pipe)\r\n- [Decorators](#decorators)\r\n  - [Input](#input)\r\n  - [Output](#output)\r\n  - [HostListener](#hostlistener)\r\n  - [ContentChild \u0026 ContentChildren](#contentchild--contentchildren)\r\n  - [ViewChild \u0026 ViewChildren](#viewchild--viewchildren)\r\n  - [HostListener](#hostlistener)\r\n  - [ContentChild \u0026 ContentChildren](#contentchild--contentchildren)\r\n  - [ViewChild \u0026 ViewChildren](#viewchild--viewchildren)\r\n- [Life Cycle Hooks](#life-cycle-hooks)\r\n  - [OnChanges](#onchanges)\r\n  - [OnInit](#oninit)\r\n  - [DoCheck](#docheck)\r\n  - [AfterViewInit](#afterviewinit)\r\n  - [AfterViewChecked](#afterviewchecked)\r\n  - [AfterContentInit](#aftercontentinit)\r\n  - [AfterContentChecked](#aftercontentchecked)\r\n  - [OnDestroy](#ondestroy)\r\n- [Forms](#forms)\r\n  - [Template Driven Forms](#template-driven-forms)\r\n  - [Reactive Forms](#reactive-forms)\r\n- [Services](#services)\r\n  - [Injectable Decorator](#injectable-decorator)\r\n  - [Dependency Injection](#dependency-injection)\r\n  - [Providers](#providers)\r\n- [Routing](#routing)\r\n  - [Router Outlet](#router-outlet)\r\n  - [Router Link](#router-link)\r\n  - [Router Link Active](#router-link-active)\r\n  - [Router State](#router-state)\r\n  - [Router Events](#router-events)\r\n  - [Router Guards](#router-guards)\r\n- [Lazy Loading](#lazy-loading)\r\n- [HTTP Client](#http-client)\r\n- [Destroy Ref](#destroy-ref)\r\n- [Http](#http)\r\n- [Module](#module)\r\n- [Router](#router)\r\n- [Route Parameter](#route-parameters)\r\n- [Route Guards](#route-guards)\r\n- [Observables](#observables-in-angular)\r\n  - [Creating Observables](#creating-observables)\r\n  - [Subscribing to Observables](#subscribing-to-observables)\r\n  - [Difference between Observables and Promises in Angular](#difference-between-observables-and-promises-in-angular)\r\n- [Unsubscribe](#unsubscribe-in-angular)\r\n- [Renderer2](#renderer2)\r\n- [JIT](#jit)\r\n- [AOT](#aot)\r\n- [Deferrable Views](#deferrable-views)\r\n- [Meta Tags](#meta-tags)\r\n  - [Title Service](#title-service)\r\n    - [Dynamic Title](#dynamic-title)\r\n  - [Meta Service](#meta-service)\r\n- [Angular Signals](#angular-signals)\r\n- [Security](#security)\r\n  - [Preventing cross-site scripting (XSS)](#preventing-cross-site-scripting-xss)\r\n  - [Angular's cross-site scripting security model](#angulars-cross-site-scripting-security-model)\r\n  - [Preventing cross-site scripting (XSS)](#preventing-cross-site-scripting-xss)\r\n  - [Angular's cross-site scripting security model](#angulars-cross-site-scripting-security-model)\r\n  - [Sanitization and security contexts](#sanitization-and-security-contexts)\r\n  - [Sanitization example](#sanitization-example)\r\n  - [Direct use of the DOM APIs and explicit sanitization calls](#direct-use-of-the-dom-apis-and-explicit-sanitization-calls)\r\n  - [Trusting safe values](#trusting-safe-values)\r\n  - [Content security policy](#content-security-policy)\r\n  - [Enforcing Trusted Types](#enforcing-trusted-types)\r\n  - [Use the AOT template compiler](#use-the-aot-template-compiler)\r\n  - [Server-side XSS protection](#server-side-xss-protection)\r\n  - [HTTP-level vulnerabilities](#http-level-vulnerabilities)\r\n  - [Cross-site request forgery](#cross-site-request-forgery)\r\n  - [HttpClient XSRF/CSRF security](#httpclient-xsrfcsrf-security)\r\n  - [Configure custom cookie/header names](#configure-custom-cookieheader-names)\r\n  - [Disabling XSRF protection](#disabling-xsrf-protection)\r\n  - [Cross-site script inclusion (XSSI)](#cross-site-script-inclusion-xssi)\r\n  - [Auditing Angular applications](#auditing-angular-applications)\r\n- [Angular Animations](#angular-animations)\r\n  - [Installing Angular Animations](#installing-angular-animations)\r\n- [Angular Universal](#angular-universal)\r\n  - [Creating an Angular Universal application](#creating-an-angular-universal-application)\r\n- [Bootstrap](#bootstrap)\r\n  - [Installing Bootstrap](#installing-bootstrap)\r\n  - [Importing Bootstrap](#importing-bootstrap)\r\n- [Angular Material](#angular-material)\r\n  - [Installing Angular Material](#installing-angular-material)\r\n  - [Importing Angular Material](#importing-angular-material)\r\n- [Tailwind CSS](#tailwind-css)\r\n  - [Installing Tailwind CSS](#installing-tailwind-css)\r\n  - [Importing Tailwind CSS](#importing-tailwind-css)\r\n- [PrimeNG](#primeng)\r\n  - [Installing PrimeNG](#installing-primeng)\r\n  - [Importing PrimeNG](#importing-primeng)\r\n- [SPA](#spa)\r\n  - [Advantages of SPA](#advantages-of-spa)\r\n- [PWA](#pwa)\r\n  - [Installing PWA](#installing-pwa)\r\n  - [Configuring PWA](#configuring-pwa)\r\n  - [Building PWA](#building-pwa)\r\n  - [Service Worker](#service-worker)\r\n  - [Features of PWA](#features-of-pwa)\r\n- [CLI Commands](#cli-commands)\r\n- [Version compatibility](#version-compatibility)\r\n- [Deploying an Angular Application](#deploying-an-angular-application)\r\n- [Imports](#imports)\r\n- [TypeScript](#typescript)\r\n- [RxJS](#rxjs)\r\n- [Learn From GitHub Repositories](#learn-more-from-github-repositories)\r\n- [Learn From Websites](#learn-more-from-websites)\r\n- [Learn From Books](#learn-more-from-books)\r\n- [Learn From YouTube Channels](#learn-from-youtube-channels)\r\n- [Learn More From Blogs Sites](#learn-more-from-blogs-sites)\r\n- [List of Online Editors/Compiler for Angular](#list-of-online-editorscompiler-for-angular)\r\n- [List of Twitter Users to Follow](#list-of-twitter-users-to-follow)\r\n- [List of LinkedIn Users to Follow](#list-of-linkedin-users-to-follow)\r\n- [List of Discord Servers to Join](#list-of-discord-servers-to-join)\r\n\r\n## Introduction\r\n\r\n**Angular** is a popular open-source framework by Google for building single-page and dynamic web applications. It offers tools and libraries for components, services, forms, routing, and HTTP client, all built with TypeScript. Angular is known for its performance, scalability, and developer productivity.\r\n\r\n### Features of Angular\r\n\r\n- **Component-Based Architecture**: Reusable, self-contained units of code that define the UI and behavior of a part of the application.\r\n- **Two-Way Data Binding**: Automatic synchronization of data between the model and the view.\r\n- **Dependency Injection**: Provides components with the services they need for better modularity and testability.\r\n- **Routing**: Powerful system for navigation between different views, supporting deep linking, lazy loading, and route guards.\r\n- **Forms**: Tools for template-driven and reactive forms, based on a model-driven approach.\r\n- **HTTP Client**: Simple API for making HTTP requests and handling responses.\r\n- **Observables**: Handles asynchronous operations and event handling.\r\n- **TypeScript**: Superset of JavaScript with static typing, better tooling, error checking, and code completion.\r\n- **Performance**: Optimized for performance with virtual DOM, lazy loading, tree shaking, and ahead-of-time compilation.\r\n- **Mobile Support**: Tools for building responsive, touch-friendly mobile applications, including PWAs.\r\n- **SEO Friendly**: Tools for server-side rendering, pre-rendering, and meta tags to improve search engine visibility.\r\n- **Community Support**: Large, active community providing support and sharing knowledge.\r\n\r\n### Difference between AngularJS vs Angular\r\n\r\n| AngularJS | Angular |\r\n|-----|-----|\r\n|Based on MVC Architecture|Based on Components|\r\n|Uses JavaScript to build the application| Uses TypeScript to build the application|\r\n|No Mobile Support|Mobile supports|\r\n|Run on only client-side|Runs on both client-side as well as server-side|\r\n|CLI not present|CLI present|\r\n|No SEO Friendly|Seo Friendly|\r\n|Performance is slow|Performance is fast|\r\n\r\n[Back to top⤴️](#table-of-contents)\r\n\r\n### Angular vs React\r\n\r\n- **Angular**: A full-fledged framework by Google for building web applications. It includes features like two-way data binding, routing, forms, and HTTP client. Ideal for large, complex applications needing a complete solution.\r\n\r\n- **React**: A JavaScript library by Facebook focused on building user interfaces. It provides a simple, declarative way to build UI components. Suitable for small to medium-sized applications requiring flexibility and customization.\r\n\r\n**Comparison**: Angular offers a complete solution with built-in features, while React focuses on the view layer, allowing developers to choose additional tools and libraries.\r\n\r\n**When to use Angular**: Best for large, complex applications needing integrated tools and scalability.\r\n\r\n**When to use React**: Best for small to medium-sized applications needing flexibility and a focus on the UI.\r\n\r\n[Back to top⤴️](#table-of-contents)\r\n\r\n## Roadmap\r\n\r\n[Angular Roadmap](https://roadmap.sh/angular)\r\n\r\n## Configuration\r\n\r\n### Prerequisites\r\n\r\n- Node.js\r\n- NPM\r\n- Angular CLI\r\n\r\n### Installation\r\n\r\nInstall the Angular CLI globally:\r\n\r\n```bash\r\nnpm install -g @angular/cli\r\n```\r\n\r\nIf you are using `pnpm`, you can use the following command:\r\n\r\n```bash\r\npnpm install -g @angular/cli\r\n```\r\n\r\nIf you are using `yarn`, you can use the following command:\r\n\r\n```bash\r\nyarn global add @angular/cli\r\n```\r\n\r\nIf you are using `bun`, you can use the following command:\r\n\r\n```bash\r\nbun install -g @angular/cli\r\n```\r\n\r\nIf you want to install a specific version of the Angular CLI, you can use the following command:\r\n\r\n```bash\r\nnpm install -g @angular/cli@version-number\r\n```\r\n\r\nIf you have already installed the Angular CLI, you can update it to the latest version using the following command:\r\n\r\n```bash\r\nnpm install -g @angular/cli@latest\r\n```\r\n\r\nCheck version\r\n\r\n```bash\r\nng version\r\n```\r\n\r\nCreate a new Angular project: (Replace `[PROJECT NAME]` with your project name)\r\n\r\n```bash\r\n# with standalone component\r\nng new [PROJECT NAME]\r\n\r\n# without standalone component\r\nng new [PROJECT NAME] --standalone=false\r\n\r\n## without routing\r\nng new [PROJECT NAME] --routing=false\r\n\r\n## without testing\r\nng new [PROJECT NAME] --skip-tests=true\r\n\r\n## without dependencies\r\nng new [PROJECT NAME] --skip-install=true\r\n\r\n## without git\r\nng new [PROJECT NAME] --skip-git=true\r\n\r\n## with experimental zonless\r\nng new [PROJECT NAME] --experimental-zoneless\r\n```\r\n\r\n**Note**: In version v16 and earlier, there is no standalone component. In version v17 and later, the standalone component is default enabled. You can enable or disable the standalone component using the `--standalone` flag while creating a new project (In this repository, an example repository is created with the latest version of Angular).\r\n\r\nNavigate to the project directory:\r\n\r\n```bash\r\ncd [PROJECT NAME]\r\n```\r\n\r\nRun the application:\r\n\r\n```bash\r\nng serve\r\n```\r\n\r\nOpen the browser and navigate to `http://localhost:4200/`.\r\n\r\nProject structure(Version 16 and earlier):\r\n\r\n```bash\r\n[PROJECT NAME]\r\n├── node_modules\r\n├── src\r\n│   ├── app\r\n│   │   ├── app.component.css\r\n│   │   ├── app.component.html\r\n│   │   ├── app.component.spec.ts\r\n│   │   ├── app.component.ts\r\n│   │   ├── app.module.ts\r\n│   │   ├── ...\r\n│   ├── assets\r\n│   │   ├── .gitkeep\r\n│   │   └── ...\r\n│   ├── index.html\r\n│   ├── main.ts\r\n│   ├── styles.css\r\n│   ├── favicon.ico\r\n│   └── ...\r\n├── .editorconfig\r\n├── .gitignore\r\n├── angular.json\r\n├── package.json\r\n├── README.md\r\n├── tsconfig.json\r\n├── tslint.json\r\n└── ...\r\n```\r\n\r\nProject structure(Version 17 and later):\r\n\r\n```bash\r\n[PROJECT NAME]\r\n├── node_modules\r\n├── public\r\n│   ├── favicon.ico\r\n│   └── ...\r\n├── src\r\n│   ├── app\r\n│   │   ├── app.component.css\r\n│   │   ├── app.component.html\r\n│   │   ├── app.component.spec.ts\r\n│   │   ├── app.component.ts\r\n│   │   ├── app.config.ts\r\n│   │   ├── app.routes.ts\r\n│   │   └── ...\r\n│   ├── index.html\r\n│   ├── main.ts\r\n│   ├── styles.css\r\n│   └── ...\r\n├── .editorconfig\r\n├── .gitignore\r\n├── angular.json\r\n├── package.json\r\n├── README.md\r\n├── tsconfig.json\r\n├── tslint.json\r\n└── ...\r\n```\r\n\r\n[Back to top⤴️](#table-of-contents)\r\n\r\n## Components\r\n\r\nComponent is the main building block of an Angular Application. It is a TypeScript class that interacts with the HTML template and provides the data and logic to the view.\r\n\r\n### Three main building blocks\r\n\r\nThere are three main building blocks of an Angular component:\r\n\r\n- Template\r\n- Class\r\n- Metadata\r\n\r\n**Template** - Defines the layout and content of the View.\r\n\r\n**Class** - Class provides the data \u0026 logic to the View.\r\n\r\n**MetaData** - Metadata Provides additional information about the component to the Angular.\r\n\r\n### Component metadata properties\r\n\r\nThere are several properties that can be defined in the component metadata:\r\n\r\n- Selector\r\n- Providers\r\n- Styles\r\n- StyleUrls\r\n- Template\r\n- TemplateUrl\r\n\r\n**Selector** - Defines the element name or CSS selector that identifies the component in the HTML template.\r\n\r\n```typescript\r\nselector: 'app-root'\r\n```\r\n\r\n**Providers** - Defines the providers of the component's dependencies.\r\n\r\n```typescript\r\nproviders: [MyService]\r\n```\r\n\r\n**styles** - Defines the inline styles for the component.\r\n\r\n```typescript\r\nstyles: ['h1 { color: red; }']\r\n```\r\n\r\n**styleUrls** - Defines an array of URLs of the stylesheets for the component.\r\n\r\n```typescript\r\nstyleUrls: ['./app.component.css']\r\n```\r\n\r\n**template** - Defines the HTML template for the component.\r\n\r\n```typescript\r\ntemplate: '\u003ch1\u003eMy Component\u003c/h1\u003e'\r\n```\r\n\r\n**templateUrl** - Defines the URL of the HTML template for the component.\r\n\r\n```typescript\r\ntemplateUrl: './app.component.html'\r\n```\r\n\r\n## Component Creation\r\n\r\n### Using Angular CLI\r\n\r\n```bash\r\nng generate component [component-name]\r\n\r\n# or\r\n\r\nng g c [component-name]\r\n```\r\n\r\n### Manual Creation\r\n\r\n**Step 1** - Create a new folder for the component inside the `src/app` folder.\r\n\r\n```bash\r\nsrc/app/[component-name]\r\n```\r\n\r\n**Step 2** - Create a new TypeScript file for the component inside the new folder.\r\n\r\n```bash\r\nsrc/app/[component-name]/[component-name].component.ts\r\n```\r\n\r\n**Step 3** - Create a new HTML file for the component inside the new folder.\r\n\r\n```bash\r\nsrc/app/[component-name]/[component-name].component.html\r\n```\r\n\r\n**Step 4** - Create a new CSS file for the component inside the new folder.\r\n\r\n```bash\r\nsrc/app/[component-name]/[component-name].component.css\r\n```\r\n\r\n**Step 5** - Import the Component class from the `@angular/core` module.\r\n\r\n```typescript\r\nimport { Component } from '@angular/core';\r\n```\r\n\r\n**Step 6** - Decorate the class with the `@Component` decorator.\r\n\r\n```typescript\r\n@Component({\r\n  selector: 'app-[component-name]',\r\n  standalone: true,\r\n  templateUrl: './[component-name].component.html',\r\n  styleUrls: ['./[component-name].component.css']\r\n})\r\n```\r\n\r\nIf you want to create a non-standalone component, set the `standalone` property to `false`. The standalone component is enabled by default in Angular v17 and v18.\r\nIn Angular v19 and later, the standalone component is enabled by default and the `standalone` property is not required. You can disable the standalone component by setting the `standalone` property to `false`.\r\n\r\n**Step 7** - Define the selector, template, and styles for the component.\r\n\r\n- selector - The selector for the component.\r\n- templateUrl - The URL of the HTML template for the component.\r\n- styleUrls - An array of URLs of the stylesheets for the component.\r\n\r\n**Step 8** - Export the class.\r\n\r\n```typescript\r\nexport class [ComponentName]Component {\r\n  // Component logic here\r\n}\r\n```\r\n\r\n**Step 9** - Import the component class in the `app.module.ts` file.\r\n\r\n```typescript\r\nimport { [ComponentName]Component } from './[component-name]/[component-name].component';\r\n```\r\n\r\n**Step 10** - Add the component to the `declarations` array in the `@NgModule` decorator.\r\n\r\n```typescript\r\ndeclarations: [\r\n  AppComponent,\r\n  [ComponentName]Component\r\n]\r\n```\r\n\r\nIf you created a standalone component, `app.module.ts` file is not required. You can import the component in the `app.component.ts` file.\r\nas shown below.\r\n\r\n```typescript\r\nimport { [ComponentName]Component } from './[component-name]/[component-name].component';\r\n\r\n@Component({\r\n  selector: 'app-root',\r\n  standalone: true,\r\n  imports: [[ComponentName]Component],\r\n  templateUrl: './app.component.html',\r\n  styleUrl: './app.component.scss'\r\n})\r\n\r\nexport class AppComponent {\r\n  title = 'app';\r\n}\r\n```\r\n\r\n**Step 11** - Use the component selector in the HTML template.\r\n\r\n```typescript\r\n\u003capp-[component-name]\u003e\u003c/app-[component-name]\u003e\r\n```\r\n\r\n**Step 12** - Run the application using the `ng serve` command.\r\n\r\n```bash\r\nng serve\r\n\r\n# or\r\n\r\nng serve --open\r\n```\r\n\r\n### Example\r\n\r\n**Creating the component files (Version 16 and earlier)** -\r\n\r\n```bash\r\n//test-component.component.ts\r\nimport { Component } from '@angular/core';\r\n\r\n@Component({\r\n  selector: 'test-component',\r\n  templateUrl: './component.component.html',\r\n  styleUrls: ['./component.component.css']\r\n})\r\n\r\nexport class TestComponent {\r\n  // Component logic here\r\n}\r\n```\r\n\r\n```html\r\n\u003c!--test.component.html--\u003e\r\n\u003ch1\u003eTest Component\u003c/h1\u003e\r\n```\r\n\r\n```css\r\n/*test.component.css*/\r\nh1 {\r\n  color: red;\r\n}\r\n```\r\n\r\n**Importing the component in the app.module.ts file** -\r\n\r\n```typescript\r\n//app.module.ts\r\nimport { BrowserModule } from '@angular/platform-browser';\r\nimport { NgModule } from '@angular/core';\r\n\r\nimport { AppComponent } from './app.component';\r\nimport { TestComponent } from './test-component.component';\r\n\r\n@NgModule({\r\n  declarations: [\r\n    AppComponent,\r\n    TestComponent\r\n  ],\r\n  imports: [\r\n    BrowserModule\r\n  ],\r\n  providers: [],\r\n  bootstrap: [AppComponent]\r\n})\r\nexport class AppModule { }\r\n```\r\n\r\n**Importing the component in the app.component.ts file** -\r\n\r\n```typescript\r\n//app.component.ts\r\nimport { Component } from '@angular/core';\r\nimport { RouterOutlet } from '@angular/router';\r\nimport { TestComponent } from './test-component.component';\r\n\r\n@Component({\r\n  selector: 'app-root',\r\n  templateUrl: './app.component.html',\r\n  styleUrl: './app.component.scss'\r\n})\r\nexport class AppComponent {\r\n  title = 'app';\r\n}\r\n```\r\n\r\n```html\r\n\u003c!--app.component.html--\u003e\r\n\u003capp-test-component\u003e\u003c/app-test-component\u003e\r\n```\r\n\r\nIn Version 16 and earlier of Angular, there is no standalone component. You need to import the component in the `app.module.ts` file. If you created a non-standalone component, you will see no standalone property in the `@Component` decorator.\r\n\r\n**Creating the component files (Version 17 and 18)** -\r\n\r\n```bash\r\n//test-component.component.ts\r\nimport { Component } from '@angular/core';\r\n\r\n@Component({\r\n  selector: 'app-test-component',\r\n  standalone: true,\r\n  templateUrl: './test-component.component.html',\r\n  styleUrls: ['./test-component.component.css']\r\n})\r\n\r\nexport class TestComponent {\r\n  // Component logic here\r\n}\r\n```\r\n\r\n```html\r\n\u003c!--test.component.html--\u003e\r\n\u003ch1\u003eTest Component\u003c/h1\u003e\r\n```\r\n\r\n```css\r\n/*test.component.css*/\r\nh1 {\r\n  color: red;\r\n}\r\n```\r\n\r\n**Importing the component in the app.component.ts file** -\r\n\r\n```typescript\r\n//app.component.ts\r\nimport { Component } from '@angular/core';\r\nimport { TestComponent } from './test-component.component';\r\n\r\n@Component({\r\n  selector: 'app-root',\r\n  imports: [TestComponent],\r\n  templateUrl: './app.component.html',\r\n  styleUrl: './app.component.scss'\r\n})\r\nexport class AppComponent {\r\n  title = 'app';\r\n}\r\n```\r\n\r\nIn version 17 and 18 of Angular, the standalone component is enabled by default with the `standalone` property set to `true` in the `@Component` decorator. You can disable the standalone component by setting the `standalone` property to `false` or not adding the standalone property in the `@Component` decorator.\r\n\r\n**Creating the component files (Version 19 and later)** -\r\n\r\n```bash\r\n//test-component.component.ts\r\nimport { Component } from '@angular/core';\r\n\r\n@Component({\r\n  selector: 'app-test-component',\r\n  templateUrl: './test-component.component.html',\r\n  styleUrls: ['./test-component.component.css']\r\n})\r\n\r\nexport class TestComponent {\r\n  // Component logic here\r\n}\r\n```\r\n\r\n```html\r\n\u003c!--test.component.html--\u003e\r\n\u003ch1\u003eTest Component\u003c/h1\u003e\r\n```\r\n\r\n```css\r\n/*test.component.css*/\r\nh1 {\r\n  color: red;\r\n}\r\n```\r\n\r\n**Importing the component in the app.component.ts file** -\r\n\r\n```typescript\r\n//app.component.ts\r\nimport { Component } from '@angular/core';\r\nimport { TestComponent } from './test-component.component';\r\n\r\n@Component({\r\n  selector: 'app-root',\r\n  imports: [TestComponent],\r\n  templateUrl: './app.component.html',\r\n  styleUrl: './app.component.scss'\r\n})\r\nexport class AppComponent {\r\n  title = 'app';\r\n}\r\n```\r\n\r\n```html\r\n\u003c!--app.component.html--\u003e\r\n\u003capp-test-component\u003e\u003c/app-test-component\u003e\r\n```\r\n\r\nIn version 19 and later of Angular, the standalone component is enabled by default. You can disable the standalone component by setting the `standalone` property to `false` in the `@Component` decorator.\r\n\r\nInside app folder, `app.config.ts` file is created by default in version 17 and later of Angular. And `app.routes.ts` file is created by default in version 17 and later of Angular.\r\n\r\n```typescript\r\n// app.config.ts\r\nimport { ApplicationConfig, provideZoneChangeDetection } from '@angular/core';\r\nimport { provideRouter } from '@angular/router';\r\n\r\nimport { routes } from './app.routes';\r\n\r\nexport const appConfig: ApplicationConfig = {\r\n  providers: [\r\n    provideZoneChangeDetection({ eventCoalescing: true }),\r\n    provideRouter(routes),\r\n  ],\r\n};\r\n```\r\n\r\n```typescript\r\n// app.routes.ts\r\nimport { Routes } from '@angular/router';\r\n\r\nexport const routes: Routes = [];\r\n```\r\n\r\nYou can import the component in the `app.component.ts` file and use the component selector in the HTML template.\r\n\r\n**Creating the inline Template \u0026 StyleUrls** -\r\n\r\n```typescript\r\nimport { Component } from '@angular/core';\r\n \r\n@Component({\r\n  selector: 'app-root',\r\n  template: '\u003ch1\u003e {{title}} works \u003c/h1\u003e',\r\n  styles: ['h1 { font-weight: bold; }']\r\n})\r\nexport class AppComponent {\r\n  title = 'app';\r\n}\r\n```\r\n\r\n[Back to top⤴️](#table-of-contents)\r\n\r\n## Scope\r\n\r\nIn Angular, the scope of a variable determines where it can be accessed:\r\n\r\n- **Global Scope**: Accessible anywhere in the application.\r\n- **Local Scope**: Accessible only within a specific function or block.\r\n- **Component Scope**: Accessible within a component and its child components.\r\n\r\n### Global Scope\r\n\r\nAccessible from anywhere in the application; defined outside any function or block.\r\n\r\nExample :\r\n\r\n```typescript\r\n// Global Scope\r\nlet globalVariable = 'Global Variable';\r\n\r\nfunction testFunction() {\r\n  console.log(globalVariable); // Output: Global Variable\r\n}\r\n\r\ntestFunction();\r\n```\r\n\r\nExample in Angular :\r\n\r\n```typescript\r\nimport { Component } from '@angular/core';\r\n\r\n// Global Scope\r\nlet globalVariable = 'Global Variable';\r\n\r\n@Component({\r\n  selector: 'app-root',\r\n  templateUrl: './app.component.html',\r\n  styleUrls: ['./app.component.css']\r\n})\r\n\r\nexport class AppComponent {\r\n  title = globalVariable;\r\n}\r\n```\r\n\r\n```html\r\n\u003c!--app.component.html--\u003e\r\n\u003ch1\u003e{{ title }}\u003c/h1\u003e\r\n```\r\n\r\n### Local Scope\r\n\r\nAccessible only within the function or block where defined.\r\n\r\nExample :\r\n\r\n```typescript\r\nfunction testFunction() {\r\n  // Local Scope\r\n  let localVariable = 'Local Variable';\r\n  console.log(localVariable); // Output: Local Variable\r\n}\r\n\r\ntestFunction();\r\nconsole.log(localVariable); // Error: localVariable is not defined\r\n```\r\n\r\nExample in Angular :\r\n\r\n```typescript\r\nimport { Component } from '@angular/core';\r\n\r\n@Component({\r\n  selector: 'app-root',\r\n  templateUrl: './app.component.html',\r\n  styleUrls: ['./app.component.css']\r\n})\r\n\r\nexport class AppComponent {\r\n  testFunction() {\r\n    // Local Scope\r\n    let localVariable = 'Local Variable';\r\n    console.log(localVariable); // Output: Local Variable\r\n  }\r\n}\r\n```\r\n\r\n```html\r\n\u003c!--app.component.html--\u003e\r\n\u003cbutton (click)=\"testFunction()\"\u003eTest Function\u003c/button\u003e\r\n```\r\n\r\n### Component Scope\r\n\r\nAccessible within the component and its children.\r\n\r\nExample :\r\n\r\n```typescript\r\nimport { Component } from '@angular/core';\r\n\r\n@Component({\r\n  selector: 'app-root',\r\n  templateUrl: './app.component.html',\r\n  styleUrls: ['./app.component.css']\r\n})\r\n\r\nexport class AppComponent {\r\n  // Component Scope\r\n  title = 'app';\r\n}\r\n```\r\n\r\n```html\r\n\u003c!--app.component.html--\u003e\r\n\u003ch1\u003e{{ title }}\u003c/h1\u003e\r\n```\r\n\r\n[Back to top⤴️](#table-of-contents)\r\n\r\n## View Encapsulation\r\n\r\nControls how styles are applied to components. By default, Angular uses Emulated View Encapsulation, scoping styles to the component.\r\n\r\n### Emulated View Encapsulation\r\n\r\nDefault mode in Angular, emulating shadow DOM to scope styles to the component.\r\n\r\n```typescript\r\nimport { Component, ViewEncapsulation } from '@angular/core';\r\n\r\n@Component({\r\n  selector: 'app-root',\r\n  templateUrl: './app.component.html',\r\n  styleUrls: ['./app.component.css'],\r\n  encapsulation: ViewEncapsulation.Emulated\r\n})\r\nexport class AppComponent {\r\n  title = 'app';\r\n}\r\n```\r\n\r\n[Stackblitz Example](https://stackblitz.com/edit/stackblitz-starters-xfz4uk?file=src%2Fmain.ts)\r\n\r\n### Shadow DOM View Encapsulation\r\n\r\nUses native shadow DOM to encapsulate styles within the component, preventing them from affecting other components.\r\n\r\n```typescript\r\nimport { Component, ViewEncapsulation } from '@angular/core';\r\n\r\n@Component({\r\n  selector: 'app-root',\r\n  templateUrl: './app.component.html',\r\n  styleUrls: ['./app.component.css'],\r\n  encapsulation: ViewEncapsulation.ShadowDom\r\n})\r\nexport class AppComponent {\r\n  title = 'app';\r\n}\r\n```\r\n\r\n[Stackblitz Example](https://stackblitz.com/edit/stackblitz-starters-cc1rfn?file=src%2Fmain.ts)\r\n\r\n### None View Encapsulation\r\n\r\nDisables encapsulation; styles can affect other components.\r\n\r\n```typescript\r\nimport { Component, ViewEncapsulation } from '@angular/core';\r\n\r\n@Component({\r\n  selector: 'app-root',\r\n  templateUrl: './app.component.html',\r\n  styleUrls: ['./app.component.css'],\r\n  encapsulation: ViewEncapsulation.None\r\n})\r\nexport class AppComponent {\r\n  title = 'app';\r\n}\r\n```\r\n\r\n[Stackblitz Example](https://stackblitz.com/edit/stackblitz-starters-gzsxag?file=src%2Fmain.ts)\r\n\r\n[Back to top⤴️](#table-of-contents)\r\n\r\n## Component Communication\r\n\r\nPassing data between Angular components using Input/Output decorators, EventEmitter, and services.\r\n\r\n### Parent to Child\r\n\r\n**Input Decorator** - The `@Input` decorator is used to pass data from a parent component to a child component. It allows the parent component to bind a property to the child component.\r\n\r\nExample :\r\n\r\n```typescript\r\nimport { Component, Input } from '@angular/core';\r\n\r\n@Component({\r\n  selector: 'app-child',\r\n  templateUrl: './child.component.html',\r\n  styleUrls: ['./child.component.css']\r\n})\r\n\r\nexport class ChildComponent {\r\n  @Input() message: string;\r\n}\r\n```\r\n\r\n```html\r\n\u003c!--child.component.html--\u003e\r\n\u003cp\u003e{{ message }}\u003c/p\u003e\r\n```\r\n\r\n```typescript\r\nimport { Component } from '@angular/core';\r\n\r\n@Component({\r\n  selector: 'app-parent',\r\n  templateUrl: './parent.component.html',\r\n  styleUrls: ['./parent.component.css']\r\n})\r\n\r\nexport class ParentComponent {\r\n  message = 'Hello from parent component';\r\n}\r\n```\r\n\r\n```html\r\n\u003c!--parent.component.html--\u003e\r\n\u003capp-child [message]=\"message\"\u003e\u003c/app-child\u003e\r\n```\r\n\r\n[Stackblitz Example](https://stackblitz.com/edit/stackblitz-starters-qqjcgn?file=src%2Fmain.ts)\r\n\r\n### Child to Parent\r\n\r\n**Output Decorator** - The `@Output` decorator is used to pass data from a child component to a parent component. It allows the child component to emit events that the parent component can listen to.\r\n\r\nExample :\r\n\r\n```typescript\r\nimport { Component, Output, EventEmitter } from '@angular/core';\r\n\r\n@Component({\r\n  selector: 'app-child',\r\n  templateUrl: './child.component.html',\r\n  styleUrls: ['./child.component.css']\r\n})\r\n\r\nexport class ChildComponent {\r\n  @Output() messageEvent = new EventEmitter\u003cstring\u003e();\r\n\r\n  sendMessage() {\r\n    this.messageEvent.emit('Hello from child component');\r\n  }\r\n}\r\n```\r\n\r\n```html\r\n\u003c!--child.component.html--\u003e\r\n\u003cbutton (click)=\"sendMessage()\"\u003eSend Message\u003c/button\u003e\r\n```\r\n\r\n```typescript\r\nimport { Component } from '@angular/core';\r\n\r\n@Component({\r\n  selector: 'app-parent',\r\n  templateUrl: './parent.component.html',\r\n  styleUrls: ['./parent.component.css']\r\n})\r\n\r\nexport class ParentComponent {\r\n  message: string;\r\n\r\n  receiveMessage($event) {\r\n    this.message = $event;\r\n  }\r\n}\r\n```\r\n\r\n```html\r\n\u003c!--parent.component.html--\u003e\r\n\u003capp-child (messageEvent)=\"receiveMessage($event)\"\u003e\u003c/app-child\u003e\r\n\u003cp\u003e{{ message }}\u003c/p\u003e\r\n```\r\n\r\n[Stackblitz Example](https://stackblitz.com/edit/stackblitz-starters-4qgrhm?file=src%2Fmain.ts)\r\n\r\n[Back to top⤴️](#table-of-contents)\r\n\r\n## Siblings to Siblings Communication\r\n\r\n**Using Services** - Services are a way to share data and functionality between components in Angular. You can create a service that holds the data and methods that need to be shared between components.\r\n\r\nExample 1 :\r\n\r\n```typescript\r\nimport { Injectable } from '@angular/core';\r\n\r\n@Injectable({\r\n  providedIn: 'root'\r\n})\r\n\r\nexport class DataService {\r\n  message: string;\r\n\r\n  setMessage(message: string) {\r\n    this.message = message;\r\n  }\r\n\r\n  getMessage() {\r\n    return this.message;\r\n  }\r\n}\r\n```\r\n\r\n```typescript\r\nimport { Component } from '@angular/core';\r\nimport { DataService } from './data.service';\r\n\r\n@Component({\r\n  selector: 'app-sibling1',\r\n  templateUrl: './sibling1.component.html',\r\n  styleUrls: ['./sibling1.component.css']\r\n})\r\n\r\nexport class Sibling1Component {\r\n  message: string;\r\n\r\n  constructor(private dataService: DataService) {}\r\n\r\n  sendMessage() {\r\n    this.dataService.setMessage('Hello from sibling1 component');\r\n  }\r\n}\r\n```\r\n\r\n```html\r\n\u003c!--sibling1.component.html--\u003e\r\n\u003cbutton (click)=\"sendMessage()\"\u003eSend Message\u003c/button\u003e\r\n```\r\n\r\n```typescript\r\nimport { Component } from '@angular/core';\r\nimport { DataService } from './data.service';\r\n\r\n@Component({\r\n  selector: 'app-sibling2',\r\n  templateUrl: './sibling2.component.html',\r\n  styleUrls: ['./sibling2.component.css']\r\n})\r\n\r\nexport class Sibling2Component {\r\n  message: string;\r\n\r\n  constructor(private dataService: DataService) {}\r\n\r\n  receiveMessage() {\r\n    this.message = this.dataService.getMessage();\r\n  }\r\n}\r\n```\r\n\r\n```html\r\n\u003c!--sibling2.component.html--\u003e\r\n\u003cp\u003e{{ message }}\u003c/p\u003e\r\n\u003cbutton (click)=\"receiveMessage()\"\u003eReceive Message\u003c/button\u003e\r\n```\r\n\r\n[Stackblitz Example](https://stackblitz.com/edit/stackblitz-starters-uvqypy?file=src%2Fmain.ts)\r\n\r\nExample 2 :\r\n\r\n**Using RxJS Subjects** - RxJS Subjects are a way to share data and events between components in Angular. You can create a Subject that emits events and subscribe to those events in the components.\r\n\r\n```typescript\r\nimport { Injectable } from '@angular/core';\r\nimport { Subject } from 'rxjs';\r\n\r\n@Injectable({\r\n  providedIn: 'root'\r\n})\r\n\r\nexport class DataService {\r\n  message = new Subject\u003cstring\u003e();\r\n\r\n  setMessage(message: string) {\r\n    this.message.next(message);\r\n  }\r\n}\r\n```\r\n\r\n```typescript\r\nimport { Component } from '@angular/core';\r\nimport { DataService } from './data.service';\r\n\r\n@Component({\r\n  selector: 'app-sibling1',\r\n  templateUrl: './sibling1.component.html',\r\n  styleUrls: ['./sibling1.component.css']\r\n})\r\n\r\nexport class Sibling1Component {\r\n  message: string;\r\n\r\n  constructor(private dataService: DataService) {}\r\n\r\n  sendMessage() {\r\n    this.dataService.setMessage('Hello from sibling1 component');\r\n  }\r\n}\r\n```\r\n\r\n```html\r\n\u003c!--sibling1.component.html--\u003e\r\n\u003cbutton (click)=\"sendMessage()\"\u003eSend Message\u003c/button\u003e\r\n```\r\n\r\n```typescript\r\nimport { Component } from '@angular/core';\r\nimport { DataService } from './data.service';\r\n\r\n@Component({\r\n  selector: 'app-sibling2',\r\n  templateUrl: './sibling2.component.html',\r\n  styleUrls: ['./sibling2.component.css']\r\n})\r\n\r\nexport class Sibling2Component {\r\n  message: string;\r\n\r\n  constructor(private dataService: DataService) {}\r\n\r\n  ngOnInit() {\r\n    this.dataService.message.subscribe(message =\u003e {\r\n      this.message = message;\r\n    });\r\n  }\r\n}\r\n```\r\n\r\n```html\r\n\u003c!--sibling2.component.html--\u003e\r\n\u003cp\u003e{{ message }}\u003c/p\u003e\r\n```\r\n\r\nExample 3 :\r\n\r\n**Using ViewChild and ViewChildren** - ViewChild and ViewChildren are a way to access child components in Angular. You can use ViewChild to access a single child component and ViewChildren to access multiple child components.\r\n\r\n```typescript\r\nimport { Component, ViewChild } from '@angular/core';\r\nimport { Sibling2Component } from './sibling2.component';\r\n\r\n@Component({\r\n  selector: 'app-sibling1',\r\n  templateUrl: './sibling1.component.html',\r\n  styleUrls: ['./sibling1.component.css']\r\n})\r\n\r\nexport class Sibling1Component {\r\n  @ViewChild(Sibling2Component) sibling2: Sibling2Component;\r\n\r\n  sendMessage() {\r\n    this.sibling2.message = 'Hello from sibling1 component';\r\n  }\r\n}\r\n```\r\n\r\n```html\r\n\u003c!--sibling1.component.html--\u003e\r\n\u003cbutton (click)=\"sendMessage()\"\u003eSend Message\u003c/button\u003e\r\n\u003capp-sibling2\u003e\u003c/app-sibling2\u003e\r\n```\r\n\r\n```typescript\r\nimport { Component } from '@angular/core';\r\n\r\n@Component({\r\n  selector: 'app-sibling2',\r\n  templateUrl: './sibling2.component.html',\r\n  styleUrls: ['./sibling2.component.css']\r\n})\r\n\r\nexport class Sibling2Component {\r\n  message: string;\r\n}\r\n```\r\n\r\n```html\r\n\u003c!--sibling2.component.html--\u003e\r\n\u003cp\u003e{{ message }}\u003c/p\u003e\r\n```\r\n\r\n[Stackblitz Example](https://stackblitz.com/edit/stackblitz-starters-nezkvf?file=src%2Fmain.ts)\r\n\r\n[Back to top⤴️](#table-of-contents)\r\n\r\n## Standalone Components\r\n\r\nA standalone component is a type of component which is not part of any Angular module. It provides a simplified way to build Angular applications by reducing the need for NgModules. Standalone components are self-contained and declare their own dependencies.\r\n\r\n### Creating a Standalone Component\r\n\r\n```typescript\r\nimport { Component } from '@angular/core';\r\nimport { CommonModule } from '@angular/common';\r\n\r\n@Component({\r\n  selector: 'app-standalone',\r\n  standalone: true, // Mark as standalone\r\n  imports: [CommonModule], // Import required dependencies\r\n  template: `\r\n    \u003ch1\u003eStandalone Component\u003c/h1\u003e\r\n    \u003cp\u003eThis is a self-contained component\u003c/p\u003e\r\n  `\r\n})\r\nexport class StandaloneComponent {\r\n  // Component logic here\r\n}\r\n```\r\n\r\n### Key Features of Standalone Components\r\n\r\n- **Self-contained**: Declares its own dependencies through the imports array\r\n- **No NgModule required**: Can be used without declaring in a module\r\n- **Easier testing**: Simpler to test due to explicit dependencies\r\n- **Better tree-shaking**: Enables more efficient bundle optimization\r\n- **Simplified lazy-loading**: Can be lazy-loaded directly without module\r\n\r\n### Using Standalone Components\r\n\r\n```typescript\r\n// Importing in another standalone component\r\n@Component({\r\n  selector: 'app-parent',\r\n  standalone: true,\r\n  imports: [StandaloneComponent],\r\n  template: `\r\n    \u003capp-standalone\u003e\u003c/app-standalone\u003e\r\n  `\r\n})\r\nexport class ParentComponent {}\r\n\r\n// Bootstrapping a standalone component\r\nimport { bootstrapApplication } from '@angular/platform-browser';\r\n\r\nbootstrapApplication(AppComponent, {\r\n  providers: [\r\n    // Root providers here\r\n  ]\r\n});\r\n```\r\n\r\n### Converting to Standalone\r\n\r\nTo convert an existing component to standalone:\r\n\r\n1. Add `standalone: true` to the component decorator\r\n2. Move dependencies from NgModule imports to component imports\r\n3. Remove component declaration from NgModule\r\n4. Import required dependencies directly in the component\r\n\r\n[Back to top⤴️](#table-of-contents)\r\n\r\n## Data binding\r\n\r\nData binding is a core feature of Angular that allows you to bind data between the component's class and the HTML template. There are two types of data binding in Angular:\r\n\r\nThere are two types of data binding in Angular:\r\n\r\n- **One-way binding** - This allows for passing data from the component's class to the HTML template or vice-versa.\r\n\r\n- **Two-way binding** - This allows for binding a property of an HTML element to a property in the component's class and vice-versa.\r\n\r\n### One way binding\r\n\r\nOne-way binding allows for passing data from the component's class to the HTML template.\r\n\r\nThere are several ways to achieve one-way binding in Angular, including:\r\n\r\n1. From Component to View\r\n2. From View to Component\r\n\r\n**1. From Component to View** - This allows for passing data from the component's class to the HTML template.\r\n\r\nThere are several ways to achieve one-way binding from the component to the view in Angular, including:\r\n\r\n1. Interpolation\r\n2. Property binding\r\n3. Class binding\r\n4. Style binding\r\n5. Attribute binding\r\n\r\n**Interpolation** - This allows for embedding expressions in the HTML template. It is denoted by double curly braces ({{}}).\r\n\r\nExample :\r\n\r\n```html\r\n\u003ch1\u003e{{ firstText }} {{ lastText }}\u003c/h1\u003e\r\n```\r\n\r\n```typescript\r\nimport { Component } from '@angular/core';\r\n\r\n@Component({\r\n  selector: 'my-app',\r\n  templateUrl: './app.component.html',\r\n  styleUrls: ['./app.component.css'],\r\n})\r\nexport class AppComponent {\r\n  firstText = 'Interpolation';\r\n  lastText = 'Example';\r\n}\r\n```\r\n\r\n[Stackblitz Example](https://stackblitz.com/edit/angular-ivy-zu564w?file=src%2Fapp%2Fapp.component.ts)\r\n\r\n**Property binding** - This allows for binding a property of an HTML element to a property in the component's class. It is denoted by square brackets ([]).\r\n\r\nExample :\r\n\r\n```html\r\n\u003ch1 [innerText]=\"title\"\u003e\u003c/h1\u003e\r\n\r\n\u003cbutton [disabled]=\"isDisabled\"\u003eI am disabled\u003c/button\u003e\r\n```\r\n\r\n```typescript\r\nimport { Component } from '@angular/core';\r\n\r\n@Component({\r\n  selector: 'my-app',\r\n  templateUrl: './app.component.html',\r\n  styleUrls: ['./app.component.css'],\r\n})\r\nexport class AppComponent {\r\n  title = 'Angular Property Binding Example';\r\n\r\n  isDisabled = true;\r\n}\r\n```\r\n\r\n[Stackblitz Example](https://stackblitz.com/edit/angular-ivy-vcpyoq?file=src/app/app.component.ts)\r\n\r\n**class binding** - This allows for binding a class of an HTML element to a property in the component's class. It is denoted by square brackets ([]).\r\n\r\nExample :\r\n\r\n```typescript\r\nimport { Component } from '@angular/core';\r\n\r\n@Component({\r\n  selector: 'my-app',\r\n  templateUrl: './app.component.html',\r\n  styleUrls: ['./app.component.css'],\r\n})\r\nexport class AppComponent {\r\n  isActive = false;\r\n\r\n  toggleActive() {\r\n    this.isActive = !this.isActive;\r\n  }\r\n}\r\n```\r\n\r\n```html\r\n\u003cdiv [class.active]=\"isActive\"\u003eThis div is active.\u003c/div\u003e\r\n\u003cbutton (click)=\"toggleActive()\"\u003eToggle Active\u003c/button\u003e\r\n```\r\n\r\n```css\r\n.active {\r\n  background-color: yellow;\r\n}\r\n```\r\n\r\n[Stackblitz Example](https://stackblitz.com/edit/angular-ivy-s1pkwg?file=src/app/app.component.ts)\r\n\r\n**style binding** - This allows for binding a style of an HTML element to a property in the component's class. It is denoted by square brackets ([]).\r\n\r\nExample :\r\n\r\n```typescript\r\nimport { Component } from '@angular/core';\r\n\r\n@Component({\r\n  selector: 'my-app',\r\n  templateUrl: './app.component.html',\r\n  styleUrls: ['./app.component.css'],\r\n})\r\nexport class AppComponent {\r\n  backgroundColor = 'red';\r\n  textColor = 'white';\r\n}\r\n```\r\n\r\n```html\r\n\u003cdiv [style.background-color]=\"backgroundColor\"\u003e\r\n  \u003ch1 [style.color]=\"textColor\"\u003eHello, world!\u003c/h1\u003e\r\n\u003c/div\u003e\r\n```\r\n\r\n[Stackblitz Example](https://stackblitz.com/edit/angular-ivy-w8nf7f?file=src/app/app.component.ts)\r\n\r\n**attribute binding** - This allows for binding an attribute of an HTML element to a property in the component's class. It is denoted by square brackets ([]).\r\n\r\nExample :\r\n\r\n```typescript\r\nimport { Component } from '@angular/core';\r\n\r\n@Component({\r\n  selector: 'my-app',\r\n  templateUrl: './app.component.html',\r\n  styleUrls: ['./app.component.css'],\r\n})\r\nexport class AppComponent {\r\n  imageUrl = 'https://example.com/image.jpg';\r\n  imageAlt = 'Example image';\r\n  isButtonDisabled = false;\r\n}\r\n```\r\n\r\n```html\r\n\u003cimg [attr.src]=\"imageUrl\" [attr.alt]=\"imageAlt\"\u003e\r\n\u003cbutton [attr.disabled]=\"isButtonDisabled\"\u003eClick me\u003c/button\u003e\r\n```\r\n\r\n[Stackblitz Example](https://stackblitz.com/edit/angular-ivy-bhqsgc?file=src/app/app.component.html)\r\n\r\n**b. From View to Component** - This allows for passing data from the HTML template to the component's class.\r\n\r\nThere are several ways to achieve one-way binding from the view to the component in Angular, including:\r\n\r\n1. Event binding\r\n2. ngModel\r\n\r\n**Event binding** - This allows for binding an event of an HTML element to a method in the component's class. It is denoted by parentheses (()).\r\n\r\nExample :\r\n\r\n```typescript\r\nimport { Component } from '@angular/core';\r\n\r\n@Component({\r\n  selector: 'my-app',\r\n  templateUrl: './app.component.html',\r\n  styleUrls: [ './app.component.css' ]\r\n})\r\nexport class AppComponent  {\r\n  onClick() {\r\n    console.log('Button was clicked');\r\n  }\r\n}\r\n```\r\n\r\n```html\r\n\u003ch1\u003eEvent Binding Example\u003c/h1\u003e\r\n\u003cbutton (click)=\"onClick()\"\u003eClick me\u003c/button\u003e\r\n```\r\n\r\n[Stackblitz Example](https://stackblitz.com/edit/angular-ivy-kxuxsk?file=src/app/app.component.ts)\r\n\r\n**ngModel** - The `ngModel` directive is used to create two-way data binding between an input element and a property in the component's class. It is commonly used to bind form controls to properties in the component.\r\n\r\nExample :\r\n\r\n```typescript\r\nimport { Component } from '@angular/core';\r\n\r\n@Component({\r\n  selector: 'my-app',\r\n  templateUrl: './app.component.html',\r\n  styleUrls: ['./app.component.css'],\r\n})\r\n\r\nexport class AppComponent {\r\n  name: string = '';\r\n}\r\n```\r\n\r\n```html\r\n\u003cinput [(ngModel)]=\"name\" placeholder=\"Enter your name\"\u003e\r\n\u003cp\u003eYour name is: {{name}}\u003c/p\u003e\r\n```\r\n\r\n**Remeber💡** :\r\n\r\nThe (click) calls the specified function when a user clicks on the given element (in your example, when a user clicks on a row).\r\n\r\nThe (change) event binds to HTML's onChange event. This event is fired for `\u003cinput\u003e`, `\u003cselect\u003e`, and `\u003ctextarea\u003e` elements when a change to the element's value is committed by the user.\r\n\r\nThe (change) event can also be specifically implemented by other Angular components. It is generally implemented on components where the contents of the component are changed by the user.\r\n\r\n[☝️Source of Explaination](https://stackoverflow.com/a/51127794/14292971)\r\n\r\n### Two ways binding\r\n\r\nTwo-way binding allows for binding a property of an HTML element to a property in the component's class and vice-versa. It is denoted by `[(ngModel)]`.\r\n\r\nThere are several ways to achieve two-way binding in Angular, including:\r\n\r\n1. ngModel\r\n2. ngModelChange\r\n3. change event\r\n\r\n**ngModel** - The `ngModel` directive is used to create two-way data binding between an input element and a property in the component's class. It is commonly used to bind form controls to properties in the component.\r\n\r\n```typescript\r\nimport { Component } from '@angular/core';\r\n\r\n@Component({\r\n  selector: 'my-app',\r\n  templateUrl: './app.component.html',\r\n  styleUrls: ['./app.component.css'],\r\n})\r\nexport class AppComponent {\r\n  name: string = '';\r\n}\r\n```\r\n\r\n```html\r\n\u003cinput [(ngModel)]=\"name\" placeholder=\"Enter your name\"\u003e\r\n\u003cp\u003eYour name is: {{name}}\u003c/p\u003e\r\n```\r\n\r\n[Stackblitz Example](https://stackblitz.com/edit/angular-ivy-wrru3d?file=src/app/app.component.ts)\r\n\r\n[Back to top⤴️](#table-of-contents)\r\n\r\n**ngModelChange** - The `ngModelChange` event is emitted when the value of an input element bound to `ngModel` changes. It can be used to perform additional logic when the value changes.\r\n\r\nExample :\r\n\r\n```typescript\r\nimport { Component } from '@angular/core';\r\n\r\n@Component({\r\n  selector: 'my-app',\r\n  templateUrl: './app.component.html',\r\n  styleUrls: ['./app.component.css'],\r\n})\r\n\r\nexport class AppComponent {\r\n  name: string = '';\r\n\r\n  onNameChange(value: string) {\r\n    console.log('Name changed to:', value);\r\n  }\r\n}\r\n```\r\n\r\n```html\r\n\u003cinput [(ngModel)]=\"name\" (ngModelChange)=\"onNameChange($event)\" placeholder=\"Enter your name\"\u003e\r\n\u003cp\u003eYour name is: {{name}}\u003c/p\u003e\r\n```\r\n\r\n[Stackblitz Example](https://stackblitz.com/edit/stackblitz-starters-s43hdu?file=src%2Fmain.ts)\r\n\r\n**change event** - The `change` event is emitted when the value of an input element changes. It can be used to perform additional logic when the value changes.\r\n\r\nExample :\r\n\r\n```typescript\r\nimport { Component } from '@angular/core';\r\n\r\n@Component({\r\n  selector: 'my-app',\r\n  templateUrl: './app.component.html',\r\n  styleUrls: ['./app.component.css'],\r\n})\r\n\r\nexport class AppComponent {\r\n  name: string = '';\r\n\r\n  onNameChange(value: string) {\r\n    console.log('Name changed to:', value);\r\n  }\r\n}\r\n```\r\n\r\n```html\r\n\u003cinput [(ngModel)]=\"name\" (change)=\"onNameChange($event.target.value)\" placeholder=\"Enter your name\"\u003e\r\n\u003cp\u003eYour name is: {{name}}\u003c/p\u003e\r\n```\r\n\r\n[Stackblitz Example](https://stackblitz.com/edit/stackblitz-starters-s43hdu?file=src%2Fmain.ts)\r\n\r\n[Back to top⤴️](#table-of-contents)\r\n\r\n## Directives\r\n\r\nDirectives add behaviour to an existing DOM element or an existing component instance.\r\n\r\n### Types of Directives\r\n\r\nThere are three types of directives in Angular:\r\n\r\n1. **Structural Directives** - Structural directives are used to add or remove elements from the DOM based on a condition. They are denoted by an asterisk (*) before the directive name.\r\n\r\n2. **Attribute Directives** - Attribute directives are used to change the appearance or behavior of an element. They are denoted by square brackets [] before the directive name.\r\n\r\n3. **Custom Directives** - Custom directives are user-defined directives that add custom behavior to an element. They can be used to encapsulate complex behavior and reuse it across multiple components.\r\n\r\n### Structural Directives\r\n\r\nThere are several built-in structural directives in Angular, including:\r\n\r\n1. NgIf\r\n2. NgFor\r\n3. NgSwitch\r\n\r\n**ngIf** - The `ngIf` directive is used to conditionally display elements based on the value of a given expression. It is commonly used to show or hide elements in the UI based on certain conditions.\r\n\r\nExample :\r\n\r\n```typescript\r\nimport { Component } from '@angular/core';\r\n\r\n@Component({\r\n  selector: 'my-app',\r\n  templateUrl: './app.component.html',\r\n  styleUrls: ['./app.component.css'],\r\n})\r\nexport class AppComponent {\r\n  showElement = true;\r\n}\r\n```\r\n\r\n```html\r\n\u003ch1\u003engIf Example\u003c/h1\u003e\r\n\u003cdiv *ngIf=\"showElement\"\u003e\r\n  This element will only be displayed if showElement is true.\r\n\u003c/div\u003e\r\n```\r\n\r\n[Stackblitz Example](https://stackblitz.com/edit/angular-ivy-bajfgs?file=src%2Fapp%2Fapp.component.ts)\r\n\r\n**ngFor** - The `ngFor` directive is used to iterate over a list of items and create a template for each item. It is commonly used to display a list of items in the UI.\r\n\r\nExample :\r\n\r\n```typescript\r\nimport { Component } from '@angular/core';\r\n\r\n@Component({\r\n  selector: 'my-app',\r\n  templateUrl: './app.component.html',\r\n  styleUrls: ['./app.component.css'],\r\n})\r\n\r\nexport class AppComponent {\r\n  items = ['Item 1', 'Item 2', 'Item 3'];\r\n}\r\n```\r\n\r\n```html\r\n\u003ch1\u003engFor Example\u003c/h1\u003e\r\n\u003cul\u003e\r\n  \u003cli *ngFor=\"let item of items\"\u003e{{ item }}\u003c/li\u003e\r\n\u003c/ul\u003e\r\n```\r\n\r\n[Stackblitz Example](https://stackblitz.com/edit/angular-ivy-sn3tgd?file=src%2Fapp%2Fapp.component.ts)\r\n\r\n**ngSwitch** - The `ngSwitch` directive is used to conditionally display elements based on the value of a given expression. It is similar to a switch statement in JavaScript.\r\n\r\nExample :\r\n\r\n```typescript\r\nimport { Component } from '@angular/core';\r\n\r\n@Component({\r\n  selector: 'my-app',\r\n  templateUrl: './app.component.html',\r\n  styleUrls: ['./app.component.css'],\r\n})\r\nexport class AppComponent {\r\n  value = 1;\r\n}\r\n```\r\n\r\n```html\r\n\u003ch1\u003engSwitch Example\u003c/h1\u003e\r\n\u003cdiv [ngSwitch]=\"value\"\u003e\r\n  \u003cdiv *ngSwitchCase=\"1\"\u003eCase 1\u003c/div\u003e\r\n  \u003cdiv *ngSwitchCase=\"2\"\u003eCase 2\u003c/div\u003e\r\n  \u003cdiv *ngSwitchCase=\"3\"\u003eCase 3\u003c/div\u003e\r\n  \u003cdiv *ngSwitchDefault\u003eDefault case\u003c/div\u003e\r\n\u003c/div\u003e\r\n```\r\n\r\n[Stackblitz Example](https://stackblitz.com/edit/angular-ivy-xm8ztp?file=src%2Fapp%2Fapp.component.ts)\r\n\r\n### Attribute Directives\r\n\r\nThere are several built-in attribute directives in Angular, including:\r\n\r\n1. NgClass\r\n2. NgStyle\r\n3. NgModel\r\n\r\n**ngClass** - The `ngClass` directive is used to conditionally apply CSS classes to an element based on the value of a given expression. It is commonly used to apply styles to elements based on certain conditions.\r\n\r\nExample :\r\n\r\n```typescript\r\nimport { Component } from '@angular/core';\r\n\r\n@Component({\r\n  selector: 'my-app',\r\n  templateUrl: './app.component.html',\r\n  styleUrls: ['./app.component.css'],\r\n})\r\nexport class AppComponent {\r\n  isHighlighted = true;\r\n}\r\n```\r\n\r\n```html\r\n\u003ch1\u003engClass Example\u003c/h1\u003e\r\n\u003cdiv [ngClass]=\"{ highlighted: isHighlighted }\"\u003e\r\n  This element will have the 'highlighted' class if isHighlighted is true.\r\n\u003c/div\u003e\r\n```\r\n\r\n```css\r\n.highlighted {\r\n  background-color: yellow;\r\n}\r\n```\r\n\r\n[Stackblitz Example](https://stackblitz.com/edit/angular-ivy-cn1fph?file=src%2Fapp%2Fapp.component.ts)\r\n\r\n**ngStyle** - The `ngStyle` directive is used to conditionally apply inline styles to an element based on the value of a given expression. It is commonly used to apply dynamic styles to elements based on certain conditions.\r\n\r\nExample :\r\n\r\n```typescript\r\nimport { Component } from '@angular/core';\r\n\r\n@Component({\r\n  selector: 'my-app',\r\n  templateUrl: './app.component.html',\r\n  styleUrls: ['./app.component.css'],\r\n})\r\nexport class AppComponent {\r\n  color = 'red';\r\n}\r\n```\r\n\r\n```html\r\n\u003ch1\u003engStyle Example\u003c/h1\u003e\r\n\u003cdiv [ngStyle]=\"{ color: color }\"\u003e\r\n  This element will have the color style set to the value of the color property.\r\n\u003c/div\u003e\r\n```\r\n\r\n[Stackblitz Example](https://stackblitz.com/edit/angular-ivy-zcgf1h?file=src%2Fapp%2Fapp.component.ts)\r\n\r\n**ngModel** - The `ngModel` directive is used to create two-way data binding between an input element and a property in the component's class. It is commonly used to bind form controls to properties in the component.\r\n\r\nExample :\r\n\r\n```typescript\r\nimport { Component } from '@angular/core';\r\n\r\n@Component({\r\n  selector: 'my-app',\r\n  templateUrl: './app.component.html',\r\n  styleUrls: ['./app.component.css'],\r\n})\r\nexport class AppComponent {\r\n  name: string;\r\n}\r\n```\r\n\r\n```html\r\n\u003ch1\u003engModel Example\u003c/h1\u003e\r\n\u003cform\u003e\r\n  \u003clabel for=\"name\"\u003eName:\u003c/label\u003e\r\n  \u003cinput type=\"text\" id=\"name\" [(ngModel)]=\"name\" name=\"name\" /\u003e\r\n\u003c/form\u003e\r\n```\r\n\r\n[Stackblitz Example](https://stackblitz.com/edit/angular-ivy-wrru3d?file=src%2Fapp%2Fapp.component.ts)\r\n\r\n### Custom Directives\r\n\r\nCustom directives are user-defined directives that add custom behavior to an element. They can be used to encapsulate complex behavior and reuse it across multiple components.\r\n\r\nExample :\r\n\r\n```typescript\r\nimport { Directive, ElementRef, HostListener, Input } from '@angular/core';\r\n\r\n@Directive({\r\n  selector: '[appCustomDirective]',\r\n})\r\nexport class CustomDirectiveDirective {\r\n  constructor(private el: ElementRef) {}\r\n\r\n  @HostListener('mouseenter') onMouseEnter() {\r\n    this.highlight('yellow');\r\n  }\r\n\r\n  @HostListener('mouseleave') onMouseLeave() {\r\n    this.highlight(null);\r\n  }\r\n\r\n  private highlight(color: string) {\r\n    this.el.nativeElement.style.backgroundColor = color;\r\n  }\r\n}\r\n```\r\n\r\n```typescript\r\nimport { NgModule } from '@angular/core';\r\nimport { BrowserModule } from '@angular/platform-browser';\r\nimport { FormsModule } from '@angular/forms';\r\n\r\nimport { AppComponent } from './app.component';\r\nimport { CustomDirectiveDirective } from './custom-directive.directive';\r\n\r\n@NgModule({\r\n  imports: [BrowserModule, FormsModule],\r\n  declarations: [AppComponent, CustomDirectiveDirective],\r\n  bootstrap: [AppComponent],\r\n})\r\nexport class AppModule {}\r\n```\r\n\r\n```html\r\n\u003ch1\u003eCustom Directive Element\u003c/h1\u003e\r\n\u003cdiv appCustomDirective\u003e\r\n  This element will have a yellow background when the mouse is over it.\r\n\u003c/div\u003e\r\n```\r\n\r\n[Stackblitz Example](https://stackblitz.com/edit/angular-ivy-xyv8qw?file=src%2Fapp%2Fapp.component.ts)\r\n\r\n[Back to top⤴️](#table-of-contents)\r\n\r\n### Other directives\r\n\r\nThere are several other built-in directives in Angular, including:\r\n\r\n- **ngContainer**\r\n- **ngTemplate**\r\n- **ngContent**\r\n- **ngTemplateOutlet**\r\n\r\n**ngContainer** - The `ngContainer` directive is a simple container that doesn't generate any markup in the DOM. It's mainly used as a placeholder to group and structure content within Angular templates.\r\n\r\nExample :\r\n\r\n```typescript\r\nimport { Component } from '@angular/core';\r\n\r\n@Component({\r\n  selector: 'my-app',\r\n  templateUrl: './app.component.html',\r\n  styleUrls: ['./app.component.css'],\r\n})\r\n\r\nexport class AppComponent {\r\n  condition = true;\r\n}\r\n```\r\n\r\n```html\r\n\u003ch1\u003engContainer Example\u003c/h1\u003e\r\n\u003cdiv *ngIf=\"condition\"\u003e\r\n  \u003cng-container\u003e\r\n    \u003cp\u003eContent to be conditionally rendered\u003c/p\u003e\r\n    \u003cp\u003eMore content...\u003c/p\u003e\r\n  \u003c/ng-container\u003e\r\n\u003c/div\u003e\r\n```\r\n\r\n[Stackblitz Example](https://stackblitz.com/edit/stackblitz-starters-zjr4xc?file=src%2Fmain.ts)\r\n\r\n**ngTemplate** - The `ngTemplate` directive is used to define a reusable template block that can be used later within the same component or shared across components using the ngTemplateOutlet directive.\r\n\r\nExample :\r\n\r\n```typescript\r\nimport { Component } from '@angular/core';\r\n\r\n@Component({\r\n  selector: 'my-app',\r\n  templateUrl: './app.component.html',\r\n  styleUrls: ['./app.component.css'],\r\n})\r\n\r\nexport class AppComponent {\r\n  selectedTemplate: any;\r\n}\r\n```\r\n\r\n```html\r\n\u003ch1\u003engTemplate Example\u003c/h1\u003e\r\n\u003cng-template #myTemplate\u003e\r\n  \u003cp\u003eThis is a template\u003c/p\u003e\r\n  \u003cp\u003eIt can be reused in multiple places\u003c/p\u003e\r\n\u003c/ng-template\u003e\r\n\r\n\u003cdiv\u003e\r\n  \u003cng-container *ngTemplateOutlet=\"selectedTemplate\"\u003e\u003c/ng-container\u003e\r\n\u003c/div\u003e\r\n\r\n\u003cbutton (click)=\"selectedTemplate = myTemplate\"\u003eLoad Template\u003c/button\u003e\r\n```\r\n\r\n[Stackblitz Example](https://stackblitz.com/edit/stackblitz-starters-azqjxv?file=src%2Fmain.ts)\r\n\r\n**ngContent** - The `ngContent` directive is used for content projection or transclusion. It allows you to create reusable components with customizable content.\r\n\r\nExample :\r\n\r\n```typescript\r\nimport { Component } from '@angular/core';\r\n\r\n@Component({\r\n  selector: 'app-child',\r\n  templateUrl: './child.component.html',\r\n  styleUrls: ['./child.component.css'],\r\n})\r\n\r\nexport class ChildComponent {}\r\n```\r\n\r\n```typescript\r\nimport { Component } from '@angular/core';\r\n\r\n@Component({\r\n  selector: 'app-parent',\r\n  templateUrl: './parent.component.html',\r\n  styleUrls: ['./parent.component.css'],\r\n})\r\n\r\nexport class ParentComponent {}\r\n```\r\n\r\n```html\r\n\u003c!-- Parent Component --\u003e\r\n\u003capp-child\u003e\r\n  \u003cp\u003eContent projected into the child component\u003c/p\u003e\r\n\u003c/app-child\u003e\r\n```\r\n\r\n```html\r\n\u003c!-- Child Component Template --\u003e\r\n\u003cdiv\u003e\r\n  \u003cng-content\u003e\u003c/ng-content\u003e\r\n\u003c/div\u003e\r\n```\r\n\r\n[Stackblitz Example](https://stackblitz.com/edit/stackblitz-starters-8ddr3h?file=src%2Fmain.ts)\r\n\r\n**ngTemplateOutlet** - The `ngTemplateOutlet` directive is used to render a template defined using ngTemplate. It allows you to dynamically render a template within a component's template.\r\n\r\nExample :\r\n\r\n```typescript\r\nimport { Component } from '@angular/core';\r\n\r\n@Component({\r\n  selector: 'my-app',\r\n  templateUrl: './app.component.html',\r\n  styleUrls: ['./app.component.css'],\r\n})\r\n\r\nexport class AppComponent {\r\n  selectedTemplate: any;\r\n}\r\n```\r\n\r\n```html\r\n\u003ch1\u003engTemplateOutlet Example\u003c/h1\u003e\r\n\u003cng-container *ngTemplateOutlet=\"selectedTemplate\"\u003e\u003c/ng-container\u003e\r\n\r\n\u003cng-template #template1\u003e\r\n  Template 1 content\r\n\u003c/ng-template\u003e\r\n\r\n\u003cng-template #template2\u003e\r\n  Template 2 content\r\n\u003c/ng-template\u003e\r\n\r\n\u003cbutton (click)=\"selectedTemplate = template1\"\u003eLoad Template 1\u003c/button\u003e\r\n\u003cbutton (click)=\"selectedTemplate = template2\"\u003eLoad Template 2\u003c/button\u003e\r\n```\r\n\r\n[Stackblitz Example](https://stackblitz.com/edit/stackblitz-starters-yerwcu?file=src%2Fmain.ts)\r\n\r\n## New Control Flow\r\n\r\nConditionally display content with @if, @else-if and @else\r\n\r\n```html\r\n@if (a \u003e b) {\r\n  \u003cp\u003e{{a}} is greater than {{b}}\u003c/p\u003e\r\n}\r\n```\r\n\r\n```html\r\n@if (a \u003e b) {\r\n  {{a}} is greater than {{b}}\r\n} @else if (b \u003e a) {\r\n  {{a}} is less than {{b}}\r\n} @else {\r\n  {{a}} is equal to {{b}}\r\n}\r\n```\r\n\r\nRepeat content with the @for block\r\n\r\n```html\r\n@for (item of items; track item.id) {\r\n  {{ item.name }}\r\n}\r\n```\r\n\r\nProviding a fallback for @for blocks with the @empty block\r\n\r\n```html\r\n@for (item of items; track item.name) {\r\n  \u003cli\u003e {{ item.name }}\u003c/li\u003e\r\n} @empty {\r\n  \u003cli aria-hidden=\"true\"\u003e There are no items. \u003c/li\u003e\r\n}\r\n```\r\n\r\nConditionally display content with the @switch block\r\n\r\n```html\r\n@switch (userPermissions) {\r\n  @case ('admin') {\r\n    \u003capp-admin-dashboard /\u003e\r\n  }\r\n  @case ('reviewer') {\r\n    \u003capp-reviewer-dashboard /\u003e\r\n  }\r\n  @case ('editor') {\r\n    \u003capp-editor-dashboard /\u003e\r\n  }\r\n  @default {\r\n    \u003capp-viewer-dashboard /\u003e\r\n  }\r\n}\r\n```\r\n\r\n[Back to top⤴️](#table-of-contents)\r\n\r\n## Pipes\r\n\r\nA pipe takes in data as input and transforms it to a desired output.\r\n\r\nSyntax:\r\n\r\n```text\r\n{{ data | pipe }}\r\n```\r\n\r\n```text\r\nExpression | pipeOperator[:pipeArguments]\r\n\r\n# Expression: is the expression, which you want to transform\r\n# | : is the Pipe Character\r\n# pipeOperator : name of the Pipe\r\n# pipeArguments: arguments to the Pipe\r\n```\r\n\r\n### Built-in Pipes\r\n\r\nThere are several built-in pipes in Angular, including:\r\n\r\n- **Date Pipe**\r\n- **Uppercase Pipe**\r\n- **Lowercase Pipe**\r\n- **Currency Pipe**\r\n- **Percent Pipe**\r\n- **Slice Pipe**\r\n- **Decimal/number Pipe**\r\n- **JSON Pipe**\r\n- **Async Pipe**\r\n\r\n### Date Pipe\r\n\r\nThe `date` pipe is used to format a date value according to the locale rules specified in the application.\r\n\r\n```ts\r\nimport { DatePipe } from '@angular/common';\r\nimport { Component } from '@angular/core';\r\n\r\n@Component({\r\n  selector: 'my-app',\r\n  templateUrl: './app.component.html',\r\n  styleUrls: ['./app.component.css'],\r\n})\r\nexport class AppComponent {\r\n  date = new Date();\r\n\r\n  constructor(private datePipe: DatePipe) {}\r\n\r\n  formatDate() {\r\n    return this.datePipe.transform(this.date, 'shortDate');\r\n  }\r\n}\r\n```\r\n\r\n```html\r\n\u003ch1\u003eDate Pipe Example\u003c/h1\u003e\r\n\u003cp\u003e{{ date | date: 'shortDate' }}\u003c/p\u003e\r\n```\r\n\r\n```ts\r\nimport { BrowserModule } from '@angular/platform-browser';\r\nimport { FormsModule } from '@angular/forms';\r\n\r\nimport { AppComponent } from './app.component';\r\nimport { DatePipe } from '@angular/common';\r\n\r\n@NgModule({\r\n  imports: [BrowserModule, FormsModule],\r\n  declarations: [AppComponent],\r\n  bootstrap: [AppComponent],\r\n  providers: [DatePipe],\r\n})\r\nexport class AppModule {}\r\n```\r\n\r\n[Stackblitz Example](https://stackblitz.com/edit/angular-ivy-fobnad?file=src%2Fapp%2Fapp.component.ts)\r\n\r\n### Uppercase Pipe\r\n\r\nThe `uppercase` pipe is used to transform a string to uppercase.\r\n\r\n```html\r\n\u003ch1\u003eUpper Case Pipe Example\u003c/h1\u003e\r\n\u003cp\u003e{{ name | uppercase }}\u003c/p\u003e\r\n```\r\n\r\n```ts\r\nimport { Component } from '@angular/core';\r\n\r\n@Component({\r\n  selector: 'my-app',\r\n  templateUrl: './app.component.html',\r\n  styleUrls: ['./app.component.css'],\r\n})\r\nexport class AppComponent {\r\n  name = 'Manthan Ank';\r\n}\r\n```\r\n\r\n[Stackblitz Example](https://stackblitz.com/edit/angular-ivy-hlmoxp?file=src%2Fapp%2Fapp.component.ts)\r\n\r\n### Lowercase Pipe\r\n\r\nThe `lowercase` pipe is used to transform a string to lowercase.\r\n\r\n```html\r\n\u003cp\u003e{{ name | lowercase }}\u003c/p\u003e\r\n```\r\n\r\n```ts\r\nimport { Component } from '@angular/core';\r\n\r\n@Component({\r\n  selector: 'my-app',\r\n  templateUrl: './app.component.html',\r\n  styleUrls: ['./app.component.css'],\r\n})\r\nexport class AppComponent {\r\n  name = 'Manthan Ank';\r\n}\r\n```\r\n\r\n[Stackblitz Example](https://stackblitz.com/edit/angular-ivy-6gcdgx?file=src%2Fapp%2Fapp.component.ts)\r\n\r\n### Currency Pipe\r\n\r\nThe `currency` pipe is used to format a number as currency using the locale rules specified in the application.\r\n\r\n```html\r\n\u003ch1\u003eCurrency Pipe Example\u003c/h1\u003e\r\n\u003cp\u003e{{ price | currency }}\u003c/p\u003e\r\n```\r\n\r\n```ts\r\nimport { CurrencyPipe } from '@angular/common';\r\nimport { Component } from '@angular/core';\r\n\r\n@Component({\r\n  selector: 'my-app',\r\n  templateUrl: './app.component.html',\r\n  styleUrls: ['./app.component.css'],\r\n})\r\nexport class AppComponent {\r\n  price = 100;\r\n\r\n  constructor(private currencyPipe: CurrencyPipe) { }\r\n\r\n  formatCurrency() {\r\n    return this.currencyPipe.transform(this.price, 'USD', true);\r\n  }\r\n}\r\n```\r\n\r\n```ts\r\nimport { NgModule } from '@angular/core';\r\nimport { BrowserModule } from '@angular/platform-browser';\r\nimport { FormsModule } from '@angular/forms';\r\n\r\nimport { AppComponent } from './app.component';\r\nimport { CurrencyPipe } from '@angular/common';\r\n\r\n@NgModule({\r\n  imports: [BrowserModule, FormsModule],\r\n  declarations: [AppComponent],\r\n  bootstrap: [AppComponent],\r\n  providers: [CurrencyPipe],\r\n})\r\nexport class AppModule {}\r\n```\r\n\r\n[Stackblitz Example](https://stackblitz.com/edit/angular-ivy-3fhhzz?file=src%2Fapp%2Fapp.component.ts)\r\n\r\n### Percent Pipe\r\n\r\nThe `percent` pipe is used to format a number as a percentage.\r\n\r\n```html\r\n\u003ch1\u003ePercent Pipe Example\u003c/h1\u003e\r\n\u003cp\u003e{{ percentage | percent }}\u003c/p\u003e\r\n```\r\n\r\n```ts\r\nimport { PercentPipe } from '@angular/common';\r\nimport { Component } from '@angular/core';\r\n\r\n@Component({\r\n  selector: 'my-app',\r\n  templateUrl: './app.component.html',\r\n  styleUrls: ['./app.component.css'],\r\n})\r\nexport class AppComponent {\r\n  percentage = 0.5;\r\n\r\n  constructor(private percentPipe: PercentPipe) {}\r\n\r\n  formatPercentage() {\r\n    return this.percentPipe.transform(this.percentage, '2');\r\n  }\r\n}\r\n```\r\n\r\n```ts\r\nimport { NgModule } from '@angular/core';\r\nimport { BrowserModule } from '@angular/platform-browser';\r\nimport { FormsModule } from '@angular/forms';\r\n\r\nimport { AppComponent } from './app.component';\r\nimport { HelloComponent } from './hello.component';\r\nimport { PercentPipe } from '@angular/common';\r\n\r\n@NgModule({\r\n  imports: [BrowserModule, FormsModule],\r\n  declarations: [AppComponent],\r\n  bootstrap: [AppComponent],\r\n  providers: [PercentPipe],\r\n})\r\nexport class AppModule {}\r\n```\r\n\r\n[Stackblitz Example](https://stackblitz.com/edit/angular-ivy-tccybj?file=src%2Fapp%2Fapp.component.ts)\r\n\r\n### Slice Pipe\r\n\r\nThe `slice` pipe is used to create a new array or string containing a subset of the elements of the input array or string.\r\n\r\n```typescript\r\n\u003cp\u003e{{ ['apple', 'banana', 'orange', 'mango'] | slice:1:3 }}\u003c/p\u003e\r\n```\r\n\r\n[Stackblitz Example](https://stackblitz.com/edit/angular-ivy-q88gmm?file=src%2Fapp%2Fapp.component.ts)\r\n\r\n### Decimal/number Pipe\r\n\r\nThe `number` pipe is used to format a number as text. It can be used to format a number as a percentage, currency, or decimal number.\r\n\r\n```html\r\n\u003cp\u003e{{ 123456.78 | number:'3.2-3' }}\u003c/p\u003e\r\n```\r\n\r\n[Stackblitz Example](https://stackblitz.com/edit/angular-ivy-7cwk1u?file=src%2Fapp%2Fapp.component.ts)\r\n\r\n### JSON Pipe\r\n\r\nThe `json` pipe is used to transform a JavaScript object into a JSON string.\r\n\r\n```html\r\n\u003cp\u003e{{data | json}}\u003c/p\u003e\r\n```\r\n\r\n```typescript\r\nimport { Component } from '@angular/core';\r\n\r\n@Component({\r\n  selector: 'my-app',\r\n  templateUrl: './app.component.html',\r\n  styleUrls: ['./app.component.css'],\r\n})\r\n\r\nexport class AppComponent {\r\n  data = { name: 'Manthan Ank', age: 25 };\r\n}\r\n```\r\n\r\n[Stackblitz Example](https://stackblitz.com/edit/stackblitz-starters-jgc252?file=src%2Fmain.ts)\r\n\r\n### Async Pipe\r\n\r\nThe `async` pipe is used to subscribe to an Observable or Promise and return the latest value it has emitted.\r\n\r\n```html\r\n\u003cp\u003e{{data$ | async}}\u003c/p\u003e\r\n```\r\n\r\n```typescript\r\n// DataService.service.ts\r\nimport { Injectable } from '@angular/core';\r\nimport { Observable, of } from 'rxjs';\r\n\r\n@Injectable()\r\nexport class DataService {\r\n  private data$: Observable\u003cstring\u003e;\r\n\r\n  constructor() {\r\n    // Simulating an asynchronous data source\r\n    this.data$ = of('Hello, async pipe!').pipe(\r\n      // Simulating delay\r\n      delay(2000)\r\n    );\r\n  }\r\n\r\n  getData(): Observable\u003cstring\u003e {\r\n    return this.data$;\r\n  }\r\n}\r\n```\r\n\r\n```typescript\r\n// ExampleComponent.component.ts\r\nimport { Component } from '@angular/core';\r\nimport { Observable } from 'rxjs';\r\nimport { DataService } from './data.service';\r\n\r\n@Component({\r\n  selector: 'app-example',\r\n  template: '\u003cdiv\u003e{{ data$ | async }}\u003c/div\u003e',\r\n})\r\nexport class ExampleComponent {\r\n  data$: Observable\u003cstring\u003e;\r\n\r\n  constructor(private dataService: DataService) {\r\n    this.data$ = this.dataService.getData();\r\n  }\r\n}\r\n```\r\n\r\n[Stackblitz Example](https://stackblitz.com/edit/stackblitz-starters-iatcbn?file=src%2Fmain.ts)\r\n\r\n### Impure Pipes\r\n\r\nBy default, Angular pipes are pure, meaning they are stateless and do not change unless the input value changes. However, you can create impure pipes by setting the pure property to false in the @Pipe decorator.\r\n\r\n```typescript\r\nimport { Pipe, PipeTransform } from '@angular/core';\r\n\r\n@Pipe({\r\n  name: 'impurePipe',\r\n  pure: false,\r\n})\r\n\r\nexport class ImpurePipe implements PipeTransform {\r\n  transform(value: any): any {\r\n    return value;\r\n  }\r\n}\r\n```\r\n\r\n```html\r\n\u003cp\u003e{{ data | impurePipe }}\u003c/p\u003e\r\n```\r\n\r\n```typescript\r\nimport { Component } from '@angular/core';\r\n\r\n@Component({\r\n  selector: 'my-app',\r\n  templateUrl: './app.component.html',\r\n  styleUrls: ['./app.component.css'],\r\n})\r\n\r\nexport class AppComponent {\r\n  data = 'Hello, world!';\r\n}\r\n```\r\n\r\n```typescript\r\nimport { BrowserModule } from '@angular/platform-browser';\r\nimport { FormsModule } from '@angular/forms';\r\n\r\nimport { AppComponent } from './app.component';\r\n\r\n@NgModule({\r\n  imports: [BrowserModule, FormsModule],\r\n  declarations: [AppComponent, ImpurePipe],\r\n  bootstrap: [AppComponent],\r\n})\r\nexport class AppModule {}\r\n```\r\n\r\n[Stackblitz Example](https://stackblitz.com/edit/stackblitz-starters-xy3hhp?file=src%2Fmain.ts)\r\n\r\n[Back to top⤴️](#table-of-contents)\r\n\r\n## Decorators\r\n\r\nDecorators are design patterns used to isolate the modification or decoration of a class without modifying the source code.\r\n\r\nThere are several built-in decorators in Angular, including:\r\n\r\n- **@Component**\r\n- **@Directive**\r\n- **@Injectable**\r\n- **@Pipe**\r\n- **@NgModule**\r\n- **@Input**\r\n- **@Output**\r\n- **@HostListener**\r\n- **@ContentChild**\r\n- **@ContentChildren**\r\n- **@ViewChild**\r\n- **@ViewChildren**\r\n\r\n### Component\r\n\r\nThe `@Component` decorator is used to define a new component in Angular.\r\n\r\n```ts\r\nimport { Component } from '@angular/core';\r\n\r\n@Component({\r\n  selector: 'my-app',\r\n  templateUrl: './app.component.html',\r\n  styleUrls: ['./app.component.css'],\r\n})\r\n\r\nexport class AppComponent {\r\n  title = 'My App';\r\n}\r\n```\r\n\r\n```html\r\n\u003ch1\u003e{{ title }}\u003c/h1\u003e\r\n```\r\n\r\n```typescript\r\nimport { NgModule } from '@angular/core';\r\nimport { BrowserModule } from '@angular/platform-browser';\r\nimport { FormsModule } from '@angular/forms';\r\n\r\nimport { AppComponent } from './app.component';\r\n\r\n@NgModule({\r\n  imports: [BrowserModule, FormsModule],\r\n  declarations: [AppComponent],\r\n  bootstrap: [AppComponent],\r\n})\r\n\r\nexport class AppModule {}\r\n```\r\n\r\n### Directive\r\n\r\nThe `@Directive` decorator is used to define a new directive in Angular.\r\n\r\n```ts\r\nimport { Directive, ElementRef, HostListener } from '@angular/core';\r\n\r\n@Directive({\r\n  selector: '[appCustomDirective]',\r\n})\r\n\r\nexport class CustomDirective {\r\n  constructor(private el: ElementRef) {}\r\n\r\n  @HostListener('mouseenter') onMouseEnter() {\r\n    this.highlight('yellow');\r\n  }\r\n\r\n  @HostListener('mouseleave') onMouseLeave() {\r\n    this.highlight(null);\r\n  }\r\n\r\n  private highlight(color: string) {\r\n    this.el.nativeElement.style.backgroundColor = color;\r\n  }\r\n}\r\n```\r\n\r\n```html\r\n\u003cdiv appCustomDirective\u003e\r\n  This element will have a yellow background when the mouse is over it.\r\n\u003c/div\u003e\r\n```\r\n\r\n```typescript\r\nimport { NgModule } from '@angular/core';\r\n\r\nimport { CustomDirective } from './custom.directive';\r\n\r\n@NgModule({\r\n  declarations: [CustomDirective],\r\n})\r\n\r\nexport class AppModule {}\r\n```\r\n\r\n### Injectable\r\n\r\nThe `@Injectable` decorator is used to define a new service in Angular.\r\n\r\n```ts\r\nimport { Injectable } from '@angular/core';\r\n\r\n@Injectable\r\nexport class DataService {\r\n  getData() {\r\n    return 'Hello, world!';\r\n  }\r\n}\r\n```\r\n\r\n```ts\r\nimport { Component } from '@angular/core';\r\nimport { DataService } from './data.service';\r\n\r\n@Component({\r\n  selector: 'my-app',\r\n  templateUrl: './app.component.html',\r\n  styleUrls: ['./app.component.css'],\r\n})\r\n\r\nexport class AppComponent {\r\n  data: string;\r\n\r\n  constructor(private dataService: DataService) {\r\n    this.data = this.dataService.getData();\r\n  }\r\n}\r\n```\r\n\r\n```typescript\r\nimport { NgModule } from '@angular/core';\r\n\r\nimport { AppComponent } from './app.component';\r\n\r\n@NgModule({\r\n  declarations: [AppComponent],\r\n  providers: [DataService],\r\n})\r\n\r\nexport class AppModule {}\r\n```\r\n\r\n### Pipe\r\n\r\nThe `@Pipe` decorator is used to define a new pipe in Angular.\r\n\r\n```ts\r\nimport { Pipe, PipeTransform } from '@angular/core';\r\n\r\n@Pipe({\r\n  name: 'customPipe',\r\n})\r\n\r\nexport class CustomPipe implements PipeTransform {\r\n  transform(value: any, args?: any): any {\r\n    return value;\r\n  }\r\n}\r\n```\r\n\r\n```html\r\n\u003ch1\u003e{{ data | customPipe }}\u003c/h1\u003e\r\n```\r\n\r\n```typescript\r\nimport { NgModule } from '@angular/core';\r\n\r\nimport { CustomPipe } from './custom.pipe';\r\n\r\n@NgModule({\r\n  declarations: [CustomPipe],\r\n})\r\n\r\nexport class AppModule {}\r\n```\r\n\r\n### NgModule\r\n\r\nThe `@NgModule` decorator is used to define a new module in Angular.\r\n\r\n```ts\r\nimport { NgModule } from '@angular/core';\r\n\r\n@NgModule({\r\n  imports: [],\r\n  declarations: [],\r\n  providers: [],\r\n  bootstrap: [],\r\n})\r\n\r\nexport class AppModule {}\r\n```\r\n\r\n```typescript\r\nimport { BrowserModule } from '@angular/platform-browser';\r\nimport { FormsModule } from '@angular/forms';\r\n\r\nimport { AppComponent } from './app.component';\r\n\r\n@NgModule({\r\n  imports: [BrowserModule, FormsModule],\r\n  declarations: [AppComponent],\r\n  bootstrap: [AppComponent],\r\n})\r\n\r\nexport class AppModule {}\r\n```\r\n\r\n### Input\r\n\r\nThe `@Input` decorator is used to pass data from a parent component to a child component.\r\n\r\n```ts\r\nimport { Component, Input, OnInit } from '@angular/core';\r\n\r\n@Component({\r\n  selector: 'app-child',\r\n  templateUrl: './child.component.html',\r\n  styleUrls: ['./child.component.css']\r\n})\r\nexport class ChildComponent implements OnInit {\r\n  @Input() message: string;\r\n  constructor() { }\r\n\r\n  ngOnInit() {}\r\n\r\n}\r\n```\r\n\r\n```ts\r\nimport { Component, OnInit } from '@angular/core';\r\n\r\n@Component({\r\n  selector: 'app-parent',\r\n  templateUrl: './parent.component.html',\r\n  styleUrls: ['./parent.component.css'],\r\n})\r\nexport class ParentComponent implements OnInit {\r\n  parentMessage = 'Hello from the parent component!';\r\n  constructor() {}\r\n\r\n  ngOnInit() {}\r\n}\r\n```\r\n\r\n```html\r\n\u003cp\u003e{{ message }}\u003c/p\u003e\r\n```\r\n\r\n```html\r\n\u003capp-child [message]=\"parentMessage\"\u003e\u003c/app-child\u003e\r\n```\r\n\r\n```html\r\n\u003ch1\u003e@Input Example\u003c/h1\u003e\r\n\u003capp-parent\u003e\u003c/app-parent\u003e\r\n```\r\n\r\n```typescript\r\nimport { NgModule } from '@angular/core';\r\nimport { BrowserModule } from '@angular/platform-browser';\r\nimport { FormsModule } from '@angular/forms';\r\n\r\nimport { AppComponent } from './app.component';\r\nimport { RouterModule } from '@angular/router';\r\nimport { ChildComponent } from './child/child.component';\r\nimport { ParentComponent } from './parent/parent.component';\r\n\r\n@NgModule({\r\n  imports: [BrowserModule, FormsModule, RouterModule],\r\n  declarations: [AppComponent, ChildComponent, ParentComponent],\r\n  bootstrap: [AppComponent],\r\n})\r\nexport class AppModule {}\r\n```\r\n\r\n### Output\r\n\r\nThe `@Output` decorator is used to pass data from a child component to a parent component.\r\n\r\n```ts\r\nimport { Component, EventEmitter, OnInit, Output } from '@angular/core';\r\n\r\n@Component({\r\n  selector: 'app-child',\r\n  templateUrl: './child.component.html',\r\n  styleUrls: ['./child.component.css'],\r\n})\r\nexport class ChildComponent implements OnInit {\r\n  @Output() messageEvent = new EventEmitter\u003cstring\u003e();\r\n\r\n  constructor() {}\r\n\r\n  ngOnInit() {}\r\n\r\n  sendMessage() {\r\n    this.messageEvent.emit('Hello from the child component!');\r\n  }\r\n}\r\n```\r\n\r\n```ts\r\nimport { Component, OnInit } from '@angular/core';\r\n\r\n@Component({\r\n  selector: 'app-parent',\r\n  templateUrl: './parent.component.html',\r\n  styleUrls: ['./parent.component.css'],\r\n})\r\nexport class ParentComponent implements OnInit {\r\n  constructor() {}\r\n\r\n  ngOnInit() {}\r\n\r\n  handleMessage(message: string) {\r\n    console.log(message);\r\n  }\r\n}\r\n```\r\n\r\n```html\r\n\u003cbutton (click)=\"sendMessage()\"\u003eSend message\u003c/button\u003e\r\n```\r\n\r\n```html\r\n\u003capp-child (messageEvent)=\"handleMessage($event)\"\u003e\u003c/app-child\u003e\r\n```\r\n\r\n```html\r\n\u003ch1\u003e@Output Decorator Example\u003c/h1\u003e\r\n\u003capp-parent\u003e\u003c/app-parent\u003e\r\n```\r\n\r\n### HostListener\r\n\r\nThe `@HostListener` decorator is used to listen for events on the host element of a directive or component.\r\n\r\n```html\r\n\u003ch1\u003e@HostListener Decorator Example\u003c/h1\u003e\r\n\u003cp\u003eClick the host element to trigger the 'click' event.\u003c/p\u003e\r\n```\r\n\r\n```ts\r\nimport { Component, HostListener } from '@angular/core';\r\n\r\n@Component({\r\n  selector: 'my-app',\r\n  templateUrl: './app.component.html',\r\n  styleUrls: ['./app.component.css'],\r\n})\r\nexport class AppComponent {\r\n  @HostListener('click')\r\n  onClick() {\r\n    console.log('The host element was clicked!');\r\n  }\r\n}\r\n```\r\n\r\n### contentChild \u0026 contentChildren\r\n\r\nThe `@ContentChild` and `@ContentChildren` decorators are used to query for content children in the component's view.\r\n\r\n```ts\r\nimport {\r\n  Component,\r\n  ContentChild,\r\n  ContentChildren,\r\n  ElementRef,\r\n  OnInit,\r\n  QueryList,\r\n} from '@angular/core';\r\n\r\n@Component({\r\n  selector: 'app-parent',\r\n  templateUrl: './parent.component.html',\r\n  styleUrls: ['./parent.component.css'],\r\n})\r\nexport class ParentComponent implements OnInit {\r\n  @ContentChild('childButton1', { static: true }) childButton1: ElementRef;\r\n  @ContentChildren('childButton2') childButtons2: QueryList\u003cElementRef\u003e;\r\n\r\n  ngAfterContentInit() {\r\n    console.log(this.childButton1.nativeElement.textContent);\r\n    this.childButtons2.forEach((button) =\u003e {\r\n      console.log(button.nativeElement.textContent);\r\n    });\r\n  }\r\n\r\n  constructor() {}\r\n\r\n  ngOnInit() {}\r\n}\r\n```\r\n\r\n```html\r\n\u003cng-content\u003e\u003c/ng-content\u003e\r\n```\r\n\r\n```html\r\n\u003ch1\u003e@ContentChild Decorator Example\u003c/h1\u003e\r\n\u003capp-parent\u003e\u003c/app-parent\u003e\r\n```\r\n\r\n### viewChild \u0026 viewChildren\r\n\r\nThe `@ViewChild` and `@ViewChildren` decorators are used to query for view children in the component's view.\r\n\r\n```ts\r\nimport { Component, ElementRef, QueryList, ViewChild, ViewChildren } from '@angular/core';\r\n\r\n@Component({\r\n  selector: 'my-app',\r\n  templateUrl: './app.component.html',\r\n  styleUrls: [ './app.component.css' ]\r\n})\r\nexport class AppComponent  {\r\n  @ViewChild('childButton1', { static: true }) childButton1: ElementRef;\r\n  @ViewChildren('childButton2') childButtons2: QueryList\u003cElementRef\u003e;\r\n\r\n  ngAfterViewInit() {\r\n    console.log(this.childButton1.nativeElement.textContent);\r\n    this.childButtons2.forEach(button =\u003e {\r\n      console.log(button.nativeElement.textContent);\r\n    });\r\n  }\r\n}\r\n```\r\n\r\n```html\r\n\u003ch1\u003e@viewChild \u0026 @viewChildren Example\u003c/h1\u003e\r\n\u003cbutton #childButton1\u003eButton 1\u003c/button\u003e\r\n\u003cbutton #childButton2\u003eButton 2\u003c/button\u003e\r\n```\r\n\r\n[Back to top⤴️](#table-of-contents)\r\n\r\n## Life Cycle Hooks\r\n\r\nAngular provides a set of lifecycle hooks that give you visibility into key moments in the component's lifecycle.\r\n\r\nThere are several lifecycle hooks in Angular, including:\r\n\r\n- **ngOnChanges**\r\n- **ngOnInit**\r\n- **ngDoCheck**\r\n- **ngAfterContentInit**\r\n- **ngAfterContentChecked**\r\n- **ngAfterViewInit**\r\n- **ngAfterViewChecked**\r\n- **ngOnDestroy**\r\n\r\n### OnChanges\r\n\r\nIt is called when the data-bound properties of a directive/component are changed. It is called before ngOnInit and whenever one or more data-bound input properties change.\r\n\r\n```html\r\n\u003cform\u003e\r\n  \u003cinput [(ngModel)]=\"message\" name=\"message\" /\u003e\r\n  \u003cbutton type=\"submit\" (click)=\"onSubmit()\"\u003eSubmit\u003c/button\u003e\r\n\u003c/form\u003e\r\n\u003cp\u003e{{ message }}\u003c/p\u003e\r\n```\r\n\r\n```ts\r\nimport {\r\n  Component,\r\n  Input,\r\n  OnChanges,\r\n  OnInit,\r\n  SimpleChanges,\r\n} from '@angular/core';\r\n\r\n@Component({\r\n  selector: 'app-test',\r\n  templateUrl: './test.component.html',\r\n  styleUrls: ['./test.component.css'],\r\n})\r\nexport class TestComponent implements OnChanges {\r\n  @Input() message: string;\r\n  prevMessage: string;\r\n\r\n  ngOnChanges(changes: SimpleChanges) {\r\n    if (changes.message) {\r\n      console.log(\r\n        `message changed from ${changes.message.previousValue} to ${changes.message.currentValue}`\r\n      );\r\n    }\r\n  }\r\n\r\n  onSubmit() {\r\n    this.prevMessage = this.message;\r\n  }\r\n}\r\n```\r\n\r\n```html\r\n\u003capp-test  [message]=\"'Hello World'\"\u003e\u003c/app-test\u003e\r\n```\r\n\r\n[Stackblitz Link](https://stackblitz.com/edit/angular-ivy-19r5mc?file=src/app/test/test.component.ts)\r\n\r\n### OnInit\r\n\r\nIt is called after Angular has initialized all data-bound properties of a directive/component. It is called only once after the first ngOnChanges.\r\n\r\n```ts\r\nimport { Component } from '@angular/core';\r\n\r\n@Component({\r\n  selector: 'my-app',\r\n  templateUrl: './app.component.html',\r\n  styleUrls: ['./app.component.css'],\r\n})\r\nexport class AppComponent {\r\n  constructor() {}\r\n\r\n  ngOnInit() {\r\n    console.log('logged from ngOnInit');\r\n  }\r\n}\r\n```\r\n\r\n[Stackblits Link](https://stackblitz.com/edit/angular-ivy-hkmssz?file=src/app/app.component.html)\r\n\r\n### DoCheck\r\n\r\nIt is called during every change detection run, and it is used to detect and act upon changes that Angular doesn't catch on its own.\r\n\r\n```ts\r\nimport { Component, DoCheck } from '@angular/core';\r\n\r\n@Component({\r\n  selector: 'my-app',\r\n  templateUrl: './app.component.html',\r\n  styleUrls: ['./app.component.css'],\r\n})\r\nexport class AppComponent implements DoCheck {\r\n  ngDoCheck() {\r\n    console.log('ngDoCheck Called');\r\n  }\r\n}\r\n```\r\n\r\n[Stackblitz Link](https://stackblitz.com/edit/angular-ivy-f5msas?file=src/app/app.component.ts)\r\n\r\n### AfterViewInit\r\n\r\nIt is called after Angular has fully initialized a component's view. It is the perfect place to put any initialization logic that depends on the view.\r\n\r\n```ts\r\nimport { AfterViewInit, Component } from '@angular/core';\r\n\r\n@Component({\r\n  selector: 'my-app',\r\n  templateUrl: './app.component.html',\r\n  styleUrls: ['./app.component.css'],\r\n})\r\nexport class AppComponent implements AfterViewInit{\r\n  \r\n  ngAfterViewInit(){\r\n    console.log(\"after view init\")\r\n  }\r\n  clickMe(){\r\n    console.log(\"link clicked\")\r\n  }\r\n}\r\n```\r\n\r\n```html\r\n\u003ca (click)=\"clickMe()\"\u003eClick me\u003c/a\u003e\r\n```\r\n\r\n[Stackblitz Link](https://stackblitz.com/edit/angular-wscf59?file=src/main.ts)\r\n\r\n### AfterViewChecked\r\n\r\nIt is called after Angular has checked the component's view and child views. It is called after ngAfterViewInit and every subsequent ngAfterContentChecked.\r\n\r\n```ts\r\nimport { AfterViewChecked, Component } from '@angular/core';\r\n\r\n@Component({\r\n  selector: 'my-app',\r\n  templateUrl: './app.component.html',\r\n  styleUrls: ['./app.component.css'],\r\n})\r\nexport class AppComponent implements AfterViewChecked {\r\n  ngAfterViewChecked(){\r\n    console.log(\"after view checked\")\r\n  }\r\n  clickMe(){\r\n    console.log(\"link clicked\")\r\n  }\r\n}\r\n```\r\n\r\n```html\r\n\u003ca (click)=\"clickMe()\"\u003eClick me\u003c/a\u003e\r\n```\r\n\r\n[Stackblitz Link](https://stackblitz.com/edit/angular-wnwfnv?file=src/main.ts)\r\n\r\n### AfterContentInit\r\n\r\nIt is called after Angular has fully initialized the content of a directive. It is the perfect place to put any initialization logic that depends on the content.\r\n\r\n```ts\r\nimport { AfterContentInit, Component } from '@angular/core';\r\n\r\n@Component({\r\n  selector: 'my-app',\r\n  templateUrl: './app.component.html',\r\n  styleUrls: ['./app.component.css'],\r\n})\r\nexport class AppComponent implements AfterContentInit {\r\n  ngAfterContentInit() {\r\n    console.log('after content init');\r\n  }\r\n  clickMe() {\r\n    console.log('clicked');\r\n  }\r\n}\r\n```\r\n\r\n```html\r\n\u003ca (click)=\"clickMe()\"\u003eClick me\u003c/a\u003e\r\n```\r\n\r\n[Stackblitz Link](https://stackblitz.com/edit/angular-qhy7cw?file=src/main.ts)\r\n\r\n### AfterContentChecked\r\n\r\nIt is called after the default change detector has completed checking all content of a directive. It is called after ngAfterContentInit and every subsequent ngAfterContentChecked.\r\n\r\n```ts\r\nimport { AfterContentInit, Component } from '@angular/core';\r\n\r\n@Component({\r\n  selector: 'my-app',\r\n  templateUrl: './app.component.html',\r\n  styleUrls: ['./app.component.css'],\r\n})\r\nexport class AppComponent implements AfterContentInit {\r\n  ngAfterContentChecked() {\r\n    console.log('after content init');\r\n  }\r\n  clickMe() {\r\n    console.log('clicked');\r\n  }\r\n}\r\n```\r\n\r\n```html\r\n\u003ca (click)=\"clickMe()\"\u003eClick me\u003c/a\u003e\r\n```\r\n\r\n[Stackblitz Link](https://stackblitz.com/edit/angular-ryx2uh?file=src/main.ts)\r\n\r\n### OnDestroy\r\n\r\nIt is called just before Angular destroys the directive/component. It is used to cleanup any resources or subscriptions that the directive/component has created.\r\n\r\n```ts\r\nimport { Component, OnDestroy, OnInit } from '@angular/core';\r\nimport { Subscription } from 'rxjs';\r\nimport { of } from 'rxjs';\r\n\r\n@Component({\r\n  selector: 'my-app',\r\n  templateUrl: './app.component.html',\r\n  styleUrls: ['./app.component.css'],\r\n})\r\nexport class AppComponent implements OnInit, OnDestroy {\r\n  private subscription: Subscription;\r\n\r\n  ngOnInit() {\r\n    const someObservable = of(1, 2, 3);\r\n    this.subscription = someObservable.subscribe((data) =\u003e {\r\n      console.log(data);\r\n    });\r\n  }\r\n\r\n  ngOnDestroy() {\r\n    this.subscription.unsubscribe();\r\n  }\r\n}\r\n```\r\n\r\n[Stackblitz Link](https://stackblitz.com/edit/angular-ivy-urqida?file=src/app/app.module.ts)\r\n\r\n[Back to top⤴️](#table-of-contents)\r\n\r\n## Forms\r\n\r\nAngular provides two types of forms:\r\n\r\n- **Template-driven forms**\r\n- **Reactive forms**\r\n\r\n### Template-driven Forms\r\n\r\nTemplate-driven forms are created using directives in the template. Angular automatically tracks the value and validity of the form controls.\r\n\r\n```html\r\n\u003cform #myForm=\"ngForm\" (ngSubmit)=\"onSubmit(myForm)\"\u003e\r\n  \u003cinput type=\"text\" name=\"name\" ngModel required /\u003e\r\n  \u003cbutton type=\"submit\"\u003eSubmit\u003c/button\u003e\r\n\u003c/form\u003e\r\n```\r\n\r\n```ts\r\nimport { Component } from '@angular/core';\r\n\r\n@Component({\r\n  selector: 'my-app',\r\n  templateUrl: './app.component.html',\r\n  styleUrls: ['./app.component.css'],\r\n})\r\nexport class AppComponent {\r\n  onSubmit(form: NgForm) {\r\n    console.log(form.value);\r\n  }\r\n}\r\n```\r\n\r\n### Reactive Forms\r\n\r\nReactive forms are created programmatically using form controls and form groups. They provide more control and flexibility compared to template-driven forms.\r\n\r\n```ts\r\nimport { Component } from '@angular/core';\r\nimport { FormBuilder, FormGroup, Validators } from '@angular/forms';\r\n\r\n@Component({\r\n  selector: 'my-app',\r\n  templateUrl: './app.component.html',\r\n  styleUrls: ['./app.component.css'],\r\n})\r\n\r\nexport class AppComponent {\r\n  form: FormGroup;\r\n\r\n  constructor(private fb: FormBuilder) {\r\n    this.form = this.fb.group({\r\n      name: ['', Validators.required],\r\n      email: ['', Validators.email],\r\n    });\r\n  }\r\n\r\n  onSubmit() {\r\n    console.log(this.form.value);\r\n  }\r\n}\r\n```\r\n\r\n```html\r\n\u003cform [formGroup]=\"form\" (ngSubmit)=\"onSubmit()\"\u003e\r\n  \u003cinput type=\"text\" formControlName=\"name\" /\u003e\r\n  \u003cinput type=\"email\" formControlName=\"email\" /\u003e\r\n  \u003cbutton type=\"submit\"\u003eSubmit\u003c/button\u003e\r\n\u003c/form\u003e\r\n```\r\n\r\n[Back to top⤴️](#table-of-contents)\r\n\r\nSet Value in Template Driven forms in Angular\r\n\r\n```html\r\n\u003cform #myForm=\"ngForm\" (ngSubmit)=\"onSubmit(myForm)\"\u003e\r\n  \u003cinput type=\"text\" name=\"name\" ngModel required /\u003e\r\n  \u003cbutton type=\"submit\"\u003eSubmit\u003c/button\u003e\r\n\u003c/form\u003e\r\n```\r\n\r\n```ts\r\nimport { Component } from '@angular/core';\r\n\r\n@Component({\r\n  selector: 'my-app',\r\n  templateUrl: './app.component.html',\r\n  styleUrls: ['./app.component.css'],\r\n})\r\n\r\nexport class AppComponent {\r\n  onSubmit(form: NgForm) {\r\n    form.setValue({ name: 'John' });\r\n  }\r\n}\r\n```\r\n\r\n[Back to top⤴️](#table-of-contents)\r\n\r\nFormBuilder in Reactive Forms\r\n  \r\n```ts\r\nimport { Component } from '@angular/core';\r\nimport { FormBuilder, FormGroup, Validators } from '@angular/forms';\r\n\r\n@Component({\r\n  selector: 'my-app',\r\n  templateUrl: './app.component.html',\r\n  styleUrls: ['./app.component.css'],\r\n})\r\n\r\nexport class AppComponent {\r\n  form: FormGroup;\r\n\r\n  constructor(private fb: FormBuilder) {\r\n    this.form = this.fb.group({\r\n      name: ['', Validators.required],\r\n      email: ['', Validators.email],\r\n    });\r\n  }\r\n\r\n  onSubmit() {\r\n    console.log(this.form.value);\r\n  }\r\n}\r\n```\r\n\r\nSetValue \u0026 PatchValue in Angular\r\n  \r\n```ts\r\nimport { Component } from '@angular/core';\r\nimport { FormBuilder, FormGroup } from '@angular/forms';\r\n\r\n@Component({\r\n  selector: 'my-app',\r\n  templateUrl: './app.component.html',\r\n  styleUrls: ['./app.component.css'],\r\n})\r\n\r\nexport class AppComponent {\r\n  form: FormGroup;\r\n\r\n  constructor(private fb: FormBuilder) {\r\n    this.form = this.fb.group({\r\n      name: '',\r\n      email: '',\r\n    });\r\n\r\n    this.form.setValue({\r\n      name: 'John',\r\n      email: 'john.doe@gmail.com',\r\n    });\r\n\r\n    this.form.patchValue({\r\n      name: 'Jane',\r\n    });\r\n  }\r\n\r\n  onSubmit() {\r\n    console.log(this.form.value);\r\n  }\r\n}\r\n```\r\n\r\nStatusChanges in Angular Forms\r\n  \r\n```ts\r\nimport { Component } from '@angular/core';\r\nimport { FormBuilder, FormGroup } from '@angular/forms';\r\n\r\n@Component({\r\n  selector: 'my-app',\r\n  templateUrl: './app.component.html',\r\n  styleUrls: ['./app.component.css'],\r\n})\r\n\r\nexport class AppComponent {\r\n  form: FormGroup;\r\n\r\n  constructor(private fb: FormBuilder) {\r\n    this.form = this.fb.group({\r\n      name: '',\r\n      email: '',\r\n    });\r\n\r\n    this.form.statusChanges.subscribe((status) =\u003e {\r\n      console.log(status);\r\n    });\r\n  }\r\n\r\n  onSubmit() {\r\n    console.log(this.form.value);\r\n  }\r\n}\r\n```\r\n\r\nValueChanges in Angular Forms\r\n\r\n```ts\r\nimport { Component } from '@angular/core';\r\nimport { FormBuilder, FormGroup } from '@angular/forms';\r\n\r\n@Component({\r\n  selector: 'my-app',\r\n  templateUrl: './app.component.html',\r\n  styleUrls: ['./app.component.css'],\r\n})\r\n\r\nexport class AppComponent {\r\n  form: FormGroup;\r\n\r\n  constructor(private fb: FormBuilder) {\r\n    this.form = this.fb.group({\r\n      name: '',\r\n      email: '',\r\n    });\r\n\r\n    this.form.valueChanges.subscribe((value) =\u003e {\r\n      console.log(value);\r\n    });\r\n  }\r\n\r\n  onSubmit() {\r\n    console.log(this.form.value);\r\n  }\r\n}\r\n```\r\n\r\nFormControl\r\n\r\n```ts\r\nimport { Component } from '@angular/core';\r\nimport { FormControl } from '@angular/forms';\r\n\r\n@Component({\r\n  selector: 'my-app',\r\n  templateUrl: './app.component.html',\r\n  styleUrls: ['./app.component.css'],\r\n})\r\n\r\nexport class AppComponent {\r\n  name = new FormControl('');\r\n\r\n  onSubmit() {\r\n    console.log(this.name.value);\r\n  }\r\n}\r\n```\r\n\r\nFormGroup\r\n\r\n```ts\r\nimport { Component } from '@angular/core';\r\nimport { FormBuilder, FormGroup } from '@angular/forms';\r\n\r\n@Component({\r\n  selector: 'my-app',\r\n  templateUrl: './app.component.html',\r\n  styleUrls: ['./app.component.css'],\r\n})\r\n\r\nexport class AppComponent {\r\n  form: FormGroup;\r\n\r\n  constructor(private fb: FormBuilder) {\r\n    this.form = this.fb.group({\r\n      name: '',\r\n      email: '',\r\n    });\r\n  }\r\n\r\n  onSubmit() {\r\n    console.log(this.form.value);\r\n  }\r\n}\r\n```\r\n\r\nFormArray Example\r\n\r\n```ts\r\nimport { Component } from '@angular/core';\r\nimport { FormBuilder, FormGroup, FormArray } from '@angular/forms';\r\n\r\n@Component({\r\n  selector: 'my-app',\r\n  templateUrl: './app.component.html',\r\n  styleUrls: ['./app.component.css'],\r\n})\r\n\r\nexport class AppComponent {\r\n  form: FormGroup;\r\n\r\n  constructor(private fb: FormBuilder) {\r\n    this.form = this.fb.group({\r\n      name: '',\r\n      emails: this.fb.array([]),\r\n    });\r\n  }\r\n\r\n  get emails() {\r\n    return this.form.get('emails') as FormArray;\r\n  }\r\n\r\n  addEmail() {\r\n    this.emails.push(this.fb.control(''));\r\n  }\r\n\r\n  removeEmail(index: number) {\r\n    this.emails.removeAt(index);\r\n  }\r\n\r\n  onSubmit() {\r\n    console.log(this.form.value);\r\n  }\r\n}\r\n```\r\n\r\n```html\r\n\u003cform [formGroup]=\"form\" (ngSubmit)=\"onSubmit()\"\u003e\r\n  \u003cinput type=\"text\" formControlName=\"name\" /\u003e\r\n  \u003cdiv formArrayName=\"emails\"\u003e\r\n    \u003cdiv *ngFor=\"let email of emails.controls; let i = index\"\u003e\r\n      \u003cinput type=\"email\" [formControlName]=\"i\" /\u003e\r\n      \u003cbutton type=\"button\" (click)=\"removeEmail(i)\"\u003eRemove\u003c/button\u003e\r\n    \u003c/div\u003e\r\n  \u003c/div\u003e\r\n  \u003cbutton type=\"button\" (click)=\"addEmail()\"\u003eAdd Email\u003c/button\u003e\r\n  \u003cbutton type=\"submit\"\u003eSubmit\u003c/button\u003e\r\n\u003c/form\u003e\r\n```\r\n\r\nBuild Dynamic or Nested Forms using FormArray\r\n\r\n```ts\r\nimport { Component } from '@angular/core';\r\nimport { FormBuilder, FormGroup, FormArray } from '@angular/forms';\r\n\r\n@Component({\r\n  selector: 'my-app',\r\n  templateUrl: './app.component.html',\r\n  styleUrls: ['./app.component.css'],\r\n})\r\n\r\nexport class AppComponent {\r\n  form: FormGroup;\r\n\r\n  constructor(private fb: FormBuilder) {\r\n    this.form = this.fb.group({\r\n      name: '',\r\n      addresses: this.fb.array([]),\r\n    });\r\n  }\r\n\r\n  get addresses() {\r\n    return this.form.get('addresses') as FormArray;\r\n  }\r\n\r\n  addAddress() {\r\n    this.addresses.push(\r\n      this.fb.group({\r\n        street: '',\r\n        city: '',\r\n        state: '',\r\n        zip: '',\r\n      })\r\n    );\r\n  }\r\n\r\n  removeAddress(index: number) {\r\n    this.addresses.removeAt(index);\r\n  }\r\n\r\n  onSubmit() {\r\n    console.log(this.form.value);\r\n  }\r\n}\r\n```\r\n\r\n```html\r\n\u003cform [formGroup]=\"form\" (ngSubmit)=\"onSubmit()\"\u003e\r\n  \u003cinput type=\"text\" formControlName=\"name\" /\u003e\r\n  \u003cdiv formArrayName=\"addresses\"\u003e\r\n    \u003cdiv *ngFor=\"let address of addresses.controls; let i = index\"\u003e\r\n      \u003cdiv [formGroupName]=\"i\"\u003e\r\n        \u003cinput type=\"text\" formControlName=\"street\" /\u003e\r\n        \u003cinput type=\"text\" formControlName=\"city\" /\u003e\r\n        \u003cinput type=\"text\" formControlName=\"state\" /\u003e\r\n        \u003cinput type=\"text\" formControlName=\"zip\" /\u003e\r\n        \u003cbutton type=\"button\" (click)=\"removeAddress(i)\"\u003eRemove\u003c/button\u003e\r\n      \u003c/div\u003e\r\n    \u003c/div\u003e\r\n  \u003c/div\u003e\r\n  \u003cbutton type=\"button\" (click)=\"addAddress()\"\u003eAdd Address\u003c/button\u003e\r\n  \u003cbutton type=\"submit\"\u003eSubmit\u003c/button\u003e\r\n\u003c/form\u003e\r\n```\r\n\r\nSetValue \u0026 PatchValue in FormArray\r\n\r\n```ts\r\nimport { Component } from '@angular/core';\r\nimport { FormBuilder, FormGroup, FormArray } from '@angular/forms';\r\n\r\n@Component({\r\n  selector: 'my-app',\r\n  templateUrl: './app.component.html',\r\n  styleUrls: ['./app.component.css'],\r\n})\r\n\r\nexport class AppComponent {\r\n  form: FormGroup;\r\n\r\n  constructor(private fb: FormBuilder) {\r\n    this.form = this.fb.group({\r\n      name: '',\r\n      addresses: this.fb.array([]),\r\n    });\r\n\r\n    this.form.setValue({\r\n      name: 'John',\r\n      addresses: [\r\n        { street: '123 Main St', city: 'Anytown', state: 'CA', zip: '12345' },\r\n        { street: '456 Elm St', city: 'Othertown', state: 'NY', zip: '67890' },\r\n      ],\r\n    });\r\n\r\n    this.form.patchValue({\r\n      name: 'Jane',\r\n    });\r\n  }\r\n\r\n  get addresses() {\r\n    return this.form.get('addresses') as FormArray;\r\n  }\r\n\r\n  addAddress() {\r\n    this.addresses.push(\r\n      this.fb.group({\r\n        street: '',\r\n        city: '',\r\n        state: '',\r\n        zip: '',\r\n      })\r\n    );\r\n  }\r\n\r\n  removeAddress(index: number) {\r\n    this.addresses.removeAt(index);\r\n  }\r\n\r\n  onSubmit() {\r\n    console.log(this.form.value);\r\n  }\r\n}\r\n```\r\n\r\n```html\r\n\u003cform [formGroup]=\"form\" (ngSubmit)=\"onSubmit()\"\u003e\r\n  \u003cinput type=\"text\" formControlName=\"name\" /\u003e\r\n  \u003cdiv formArrayName=\"addresses\"\u003e\r\n    \u003cdiv *ngFor=\"let address of addresses.controls; let i = index\"\u003e\r\n      \u003cdiv [formGroupName]=\"i\"\u003e\r\n        \u003cinput type=\"text\" formControlName=\"street\" /\u003e\r\n        \u003cinput type=\"text\" formControlName=\"city\" /\u003e\r\n        \u003cinput type=\"text\" formControlName=\"state\" /\u003e\r\n        \u003cinput type=\"text\" formControlName=\"zip\" /\u003e\r\n        \u003cbutton type=\"button\" (click)=\"removeAddress(i)\"\u003eRemove\u003c/button\u003e\r\n      \u003c/div\u003e\r\n    \u003c/div\u003e\r\n  \u003c/div\u003e\r\n  \u003cbutton type=\"button\" (click)=\"addAddress()\"\u003eAdd Address\u003c/button\u003e\r\n  \u003cbutton type=\"submit\"\u003eSubmit\u003c/button\u003e\r\n\u003c/form\u003e\r\n```\r\n\r\nSelect Options Dropdown\r\n\r\n```ts\r\nimport { Component } from '@angular/core';\r\nimport { FormBuilder, FormGroup } from '@angular/forms';\r\n\r\n@Component({\r\n  selector: 'my-app',\r\n  templateUrl: './app.component.html',\r\n  styleUrls: ['./app.component.css'],\r\n})\r\n\r\nexport class AppComponent {\r\n  form: FormGroup;\r\n\r\n  constructor(private fb: FormBuilder) {\r\n    this.form = this.fb.group({\r\n      name: '',\r\n      gender: '',\r\n    });\r\n  }\r\n\r\n  onSubmit() {\r\n    console.log(this.form.value);\r\n  }\r\n}\r\n```\r\n\r\n```html\r\n\u003cform [formGroup]=\"form\" (ngSubmit)=\"onSubmit()\"\u003e\r\n  \u003cinput type=\"text\" formControlName=\"name\" /\u003e\r\n  \u003cselect formControlName=\"gender\"\u003e\r\n    \u003coption value=\"male\"\u003eMale\u003c/option\u003e\r\n    \u003coption value=\"female\"\u003eFemale\u003c/option\u003e\r\n  \u003c/select\u003e\r\n  \u003cbutton type=\"submit\"\u003eSubmit\u003c/button\u003e\r\n\u003c/form\u003e\r\n```\r\n\r\nTyped Forms in Angular\r\n\r\n```ts\r\nimport { Component } from '@angular/core';\r\nimport { FormBuilder, FormGroup } from '@angular/forms';\r\n\r\ninterface User {\r\n  name: string;\r\n  email: string;\r\n}\r\n\r\n@Component({\r\n  selector: 'my-app',\r\n  templateUrl: './app.component.html',\r\n  styleUrls: ['./app.component.css'],\r\n})\r\n\r\nexport class AppComponent {\r\n  form: FormGroup;\r\n\r\n  constructor(private fb: FormBuilder) {\r\n    this.form = this.fb.group\u003cUser\u003e({\r\n      name: '',\r\n      email: '',\r\n    });\r\n  }\r\n\r\n  onSubmit() {\r\n    console.log(this.form.value);\r\n  }\r\n}\r\n```\r\n\r\n```html\r\n\u003cform [formGroup]=\"form\" (ngSubmit)=\"onSubmit()\"\u003e\r\n  \u003cinput type=\"text\" formControlName=\"name\" /\u003e\r\n  \u003cinput type=\"email\" formControlName=\"email\" /\u003e\r\n  \u003cbutton type=\"submit\"\u003eSubmit\u003c/button\u003e\r\n\u003c/form\u003e\r\n```\r\n\r\nFormArray in Angular\r\n\r\n```ts\r\nimport { Component } from '@angular/core';\r\nimport { FormBuilder, FormGroup } from '@angular/forms';\r\n\r\n@Component({\r\n  selector: 'my-app',\r\n  templateUrl: './app.component.html',\r\n  styleUrls: ['./app.component.css'],\r\n})\r\n\r\nexport class AppComponent {\r\n  form: FormGroup;\r\n\r\n  constructor(private fb: FormBuilder) {\r\n    this.form = this.fb.group({\r\n      name: '',\r\n      email: '',\r\n    });\r\n  }\r\n\r\n  onSubmit() {\r\n    console.log(this.form.value);\r\n  }\r\n}\r\n```\r\n\r\n```html\r\n\u003cform [formGroup]=\"form\" (ngSubmit)=\"onSubmit()\"\u003e\r\n  \u003cinput type=\"text\" formControlName=\"name\" /\u003e\r\n  \u003cinput type=\"email\" formControlName=\"email\" /\u003e\r\n  \u003cbutton type=\"submit\"\u003eSubmit\u003c/button\u003e\r\n\u003c/form\u003e\r\n```\r\n\r\n## Services\r\n\r\nServices are used to encapsulate reusable functionality that can be shared across components. They are used to fetch data from a server, perform calculations, or interact with external services.\r\n\r\n```ts\r\nimport { Injectable } from '@angular/core';\r\n\r\n@Injectable\r\nexport class DataService {\r\n  getData() {\r\n    return 'Data from the service';\r\n  }\r\n}\r\n```\r\n\r\n```ts\r\nimport { Component } from '@angular/core';\r\nimport { DataService } from './data.service';\r\n\r\n@Component({\r\n  selector: 'my-app',\r\n  templateUrl: './app.component.html',\r\n  styleUrls: ['./app.component.css'],\r\n})\r\n\r\nexport class AppComponent {\r\n  data: string;\r\n\r\n  constructor(private dataService: DataService) {\r\n    this.data = this.dataService.getData();\r\n  }\r\n}\r\n```\r\n\r\n[Back to top⤴️](#table-of-contents)\r\n\r\n### Injectable Decorator\r\n\r\nThe `@Injectable` decorator is used to define a service class that can be injected into other components or services.\r\n\r\n```ts\r\nimport { Injectable } from '@angular/core';\r\n\r\n@Injectable\r\nexport class DataService {\r\n  getData() {\r\n    return 'Data from the service';\r\n  }\r\n}\r\n```\r\n\r\n[Back to top⤴️](#table-of-contents)\r\n\r\n### Dependency Injection\r\n\r\nDependency injection is a design pattern used to create objects and manage their dependencies. It allows you to inject dependencies into a class rather than creating them within the class.\r\n\r\n```ts\r\nimport { Injectable } from '@angular/core';\r\n\r\n@Injectable\r\nexport class DataService {\r\n  getData() {\r\n    return 'Data from the service';\r\n  }\r\n}\r\n```\r\n\r\n```ts\r\nimport { Component } from '@angular/core';\r\nimport { DataService } from './data.service';\r\n\r\n@Component({\r\n  selector: 'my-app',\r\n  templateUrl: './app.component.html',\r\n  styleUrls: ['./app.component.css'],\r\n})\r\n\r\nexport class AppComponent {\r\n  data: string;\r\n\r\n  constructor(private dataService: DataService) {\r\n    this.data = this.dataService.getData();\r\n  }\r\n}\r\n```\r\n\r\nUsing `@inject` decorator is an alternative way to inject dependencies into a class.\r\n\r\n```typescript\r\nimport { Component } from '@angular/core';\r\nimport { DataService } from './data.service';\r\n\r\n@Component({\r\n  selector: 'my-app',\r\n  templateUrl: './app.component.html',\r\n  styleUrls: ['./app.component.css'],\r\n})\r\n\r\nexport class AppComponent {\r\n  data: string;\r\n  private dataService = inject(DataService);\r\n\r\n  constructor() {\r\n    this.data = this.dataService.getData();\r\n  }\r\n}\r\n```\r\n\r\n[Back to top⤴️](#table-of-contents)\r\n\r\n### Providers\r\n\r\nProviders are used to define dependencies that are injected into components, directives, pipes, and services. They are defined in the `@NgModule` decorator of the root module or feature modules.\r\n\r\n```ts\r\nimport { NgModule } from '@angular/core';\r\nimport { BrowserModule } from '@angular/platform-browser';\r\nimport { FormsModule } from '@angular/forms';\r\n\r\nimport { AppComponent } from './app.component';\r\nimport { DataService } from './data.service';\r\n\r\n@NgModule({\r\n  imports: [BrowserModule, FormsModule],\r\n  declarations: [AppComponent],\r\n  bootstrap: [AppComponent],\r\n  providers: [DataService],\r\n})\r\n\r\nexport class AppModule {}\r\n```\r\n\r\n[Back to top⤴️](#table-of-contents)\r\n\r\n## Routing\r\n\r\nRouting is used to navigate between different components in an Angular application. It allows users to move between different parts of the application by changing the URL in the browser.\r\n\r\n```ts\r\nimport { NgModule } from '@angular/core';\r\nimport { RouterModule, Routes } from '@angular/router';\r\n\r\nconst routes: Routes = [];\r\n\r\n@NgModule({\r\n  imports: [RouterModule.forRoot(routes)],\r\n  exports: [RouterModule],\r\n})\r\n\r\nexport class AppRoutingModule {}\r\n```\r\n\r\n```typescript\r\nimport { Routes } from '@angular/router';\r\n\r\nexport const routes: Routes = [];\r\n```\r\n\r\n```typescript\r\nimport { Applica","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmanthanank%2Flearn-angular","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmanthanank%2Flearn-angular","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmanthanank%2Flearn-angular/lists"}