diff --git a/.editorconfig b/.editorconfig index 59d9a3a..f166060 100644 --- a/.editorconfig +++ b/.editorconfig @@ -10,6 +10,7 @@ trim_trailing_whitespace = true [*.ts] quote_type = single +ij_typescript_use_double_quotes = false [*.md] max_line_length = off diff --git a/.github/workflows/releases.yml b/.github/workflows/releases.yml index 000be9f..a504a29 100644 --- a/.github/workflows/releases.yml +++ b/.github/workflows/releases.yml @@ -16,7 +16,7 @@ jobs: uses: TriPSs/conventional-changelog-action@v3.7.1 with: github-token: ${{ secrets.PA_TOKEN }} - version-file: './releases.json' + version-file: './releases.json,./package.json,./package-lock.json' - name: create release uses: actions/create-release@v1 diff --git a/.gitignore b/.gitignore index 0711527..cc7b141 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,4 @@ -# See http://help.github.com/ignore-files/ for more about ignoring files. +# See https://docs.github.com/get-started/getting-started-with-git/ignoring-files for more about ignoring files. # Compiled output /dist diff --git a/.vscode/launch.json b/.vscode/launch.json index 740e35a..925af83 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -4,7 +4,7 @@ "configurations": [ { "name": "ng serve", - "type": "pwa-chrome", + "type": "chrome", "request": "launch", "preLaunchTask": "npm: start", "url": "http://localhost:4200/" diff --git a/CHANGELOG.md b/CHANGELOG.md index 6ab7fcd..231bc19 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,46 +1,45 @@ -# [1.44.0](https://github.com/manthanank/learn-angular/compare/v1.43.0...v1.44.0) (2023-11-09) +# [2.5.0](https://github.com/manthanank/learn-angular/compare/v2.4.0...v2.5.0) (2024-10-03) ### Features -* update to v17 ([ab5c080](https://github.com/manthanank/learn-angular/commit/ab5c0801ac96502c419a1ec6a0568b2c0e42c681)) +* Update styles configuration and documentation ([fb62ca5](https://github.com/manthanank/learn-angular/commit/fb62ca53d010b2e3e7ab42cce348eb815ab469bc)) -# [1.43.0](https://github.com/manthanank/learn-angular/compare/v1.42.0...v1.43.0) (2023-08-24) +# [2.4.0](https://github.com/manthanank/learn-angular/compare/v2.2.0...v2.4.0) (2024-10-03) ### Features -* updated to latest ([ab9c674](https://github.com/manthanank/learn-angular/commit/ab9c674ca544af80a20dd24539bee0c12d50610f)) -* updated to latest ([c0d7cff](https://github.com/manthanank/learn-angular/commit/c0d7cff9bebcd1722ecd8a44f5111423d0a76297)) +* Update styles configuration and documentation ([c6d2f52](https://github.com/manthanank/learn-angular/commit/c6d2f5200988eb207975d29f686dfd9ae98b2664)) -# [1.42.0](https://github.com/manthanank/learn-angular/compare/v1.41.0...v1.42.0) (2023-06-21) +# [2.2.0](https://github.com/manthanank/learn-angular/compare/v2.1.0...v2.2.0) (2024-06-26) ### Features -* added angular app and updated readme.md ([39d21a3](https://github.com/manthanank/learn-angular/commit/39d21a344f4360585d1c46092d487e4775f8f594)) +* Update README.md with improved description of Angular framework ([fa07520](https://github.com/manthanank/learn-angular/commit/fa0752021f6d5c15b3b1cd8dc554dc5322fd62ec)) -# [1.41.0](https://github.com/manthanank/learn-angular/compare/v1.40.0...v1.41.0) (2023-06-19) +# [2.1.0](https://github.com/manthanank/learn-angular/compare/v1.59.0...v2.1.0) (2024-06-26) ### Features -* updated ([dd532e8](https://github.com/manthanank/learn-angular/commit/dd532e89cb7351ecda00cf348bdf68218b4d7e6d)) +* Bump version to 2.0.0 in package-lock.json, package.json, and releases.json ([b8033a2](https://github.com/manthanank/learn-angular/commit/b8033a2e13bca141b46909fa40374135b1316859)) -# [1.40.0](https://github.com/manthanank/learn-angular/compare/v1.39.0...v1.40.0) (2023-06-19) +# [1.59.0](https://github.com/manthanank/learn-angular/compare/v1.58.0...v1.59.0) (2024-05-08) ### Features -* added version compatibility table ([5a2bc5b](https://github.com/manthanank/learn-angular/commit/5a2bc5bcaeccd6a1ea85d3b1b5c2a5ebec97229f)) +* deleted issue templates ([62c5600](https://github.com/manthanank/learn-angular/commit/62c5600bf4c48df6c6e8f94a7a4dc022dc6b35c5)) diff --git a/CODE_OF_CONDUCT.md b/CODE_OF_CONDUCT.md new file mode 100644 index 0000000..82cd0f3 --- /dev/null +++ b/CODE_OF_CONDUCT.md @@ -0,0 +1,126 @@ +# Contributor Covenant Code of Conduct + +## Our Pledge + +We as members, contributors, and leaders pledge to make participation in our +community a harassment-free experience for everyone, regardless of age, body +size, visible or invisible disability, ethnicity, sex characteristics, gender +identity and expression, level of experience, education, socio-economic status, +nationality, personal appearance, race, religion, or sexual identity +and orientation. + +We pledge to act and interact in ways that contribute to an open, welcoming, +diverse, inclusive, and healthy community. + +## Our Standards + +Examples of behavior that contributes to a positive environment for our +community include: + +* Demonstrating empathy and kindness toward other people +* Being respectful of differing opinions, viewpoints, and experiences +* Giving and gracefully accepting constructive feedback +* Accepting responsibility and apologizing to those affected by our mistakes, + and learning from the experience +* Focusing on what is best not just for us as individuals, but for the + overall community + +Examples of unacceptable behavior include: + +* The use of sexualized language or imagery, and sexual attention or + advances of any kind +* Trolling, insulting or derogatory comments, and personal or political attacks +* Public or private harassment +* Publishing others' private information, such as a physical or email + address, without their explicit permission +* Other conduct which could reasonably be considered inappropriate in a + professional setting + +## Enforcement Responsibilities + +Community leaders are responsible for clarifying and enforcing our standards of +acceptable behavior and will take appropriate and fair corrective action in +response to any behavior that they deem inappropriate, threatening, offensive, +or harmful. + +Community leaders have the right and responsibility to remove, edit, or reject +comments, commits, code, wiki edits, issues, and other contributions that are +not aligned to this Code of Conduct, and will communicate reasons for moderation +decisions when appropriate. + +## Scope + +This Code of Conduct applies within all community spaces, and also applies when +an individual is officially representing the community in public spaces. +Examples of representing our community include using an official e-mail address, +posting via an official social media account, or acting as an appointed +representative at an online or offline event. + +## Enforcement + +Instances of abusive, harassing, or otherwise unacceptable behavior may be +reported to the community leaders responsible for enforcement at +[Contact Form](https://manthanank.github.io/contact). +All complaints will be reviewed and investigated promptly and fairly. + +All community leaders are obligated to respect the privacy and security of the +reporter of any incident. + +## Enforcement Guidelines + +Community leaders will follow these Community Impact Guidelines in determining +the consequences for any action they deem in violation of this Code of Conduct: + +### 1. Correction + +**Community Impact**: Use of inappropriate language or other behavior deemed +unprofessional or unwelcome in the community. + +**Consequence**: A private, written warning from community leaders, providing +clarity around the nature of the violation and an explanation of why the +behavior was inappropriate. A public apology may be requested. + +### 2. Warning + +**Community Impact**: A violation through a single incident or series +of actions. + +**Consequence**: A warning with consequences for continued behavior. No +interaction with the people involved, including unsolicited interaction with +those enforcing the Code of Conduct, for a specified period of time. This +includes avoiding interactions in community spaces as well as external channels +like social media. Violating these terms may lead to a temporary or +permanent ban. + +### 3. Temporary Ban + +**Community Impact**: A serious violation of community standards, including +sustained inappropriate behavior. + +**Consequence**: A temporary ban from any sort of interaction or public +communication with the community for a specified period of time. No public or +private interaction with the people involved, including unsolicited interaction +with those enforcing the Code of Conduct, is allowed during this period. +Violating these terms may lead to a permanent ban. + +### 4. Permanent Ban + +**Community Impact**: Demonstrating a pattern of violation of community +standards, including sustained inappropriate behavior, harassment of an +individual, or aggression toward or disparagement of classes of individuals. + +**Consequence**: A permanent ban from any sort of public interaction within +the community. + +## Attribution + +This Code of Conduct is adapted from the [Contributor Covenant][homepage], +version 2.0, available at [https://www.contributor-covenant.org/version/2/0/code_of_conduct.html](https://www.contributor-covenant.org/version/2/0/code_of_conduct.html). + +Community Impact Guidelines were inspired by [Mozilla's code of conduct +enforcement ladder](https://github.com/mozilla/diversity). + +[homepage]: https://www.contributor-covenant.org + +For answers to common questions about this code of conduct, see the FAQ at +[https://www.contributor-covenant.org/faq](https://www.contributor-covenant.org/faq). Translations are available at [https://www.contributor-covenant.org/translations](https://www.contributor-covenant.org/translations). diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md new file mode 100644 index 0000000..62fda87 --- /dev/null +++ b/CONTRIBUTING.md @@ -0,0 +1,21 @@ +# Contributing + +Thank you for considering contributing to this project! By this, you +agree to abide by the [Code Of Conduct](https://github.com/manthanank/learn-angular/blob/main/CODE_OF_CONDUCT.md). + +## How to Contribute + +- Fork the repository +- Clone the repository +- Create a new branch +- Make your changes +- Push your changes +- Create a pull request + +## Code Of Conduct + +Please read the [Code Of Conduct](https://github.com/manthanank/learn-angular/blob/main/CODE_OF_CONDUCT.md) before contributing to this project. + +## License + +This project is licensed under the MIT License - see the [LICENSE](https://github.com/manthanank/learn-angular/blob/main/LICENSE) file for details. diff --git a/Dockerfile b/Dockerfile index d7e0482..cedfbce 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,2 +1,20 @@ -FROM alpine:3.17.2 -CMD ["echo", "Hello World!"] \ No newline at end of file +# Use an official Node.js runtime as a parent image +FROM node:14 + +# Set the working directory in the container to /app +WORKDIR /app + +# Copy package.json and package-lock.json to the working directory +COPY package*.json ./ + +# Install any needed packages specified in package.json +RUN npm install + +# Bundle app source inside the docker image +COPY . . + +# Make port 8080 available to the world outside this container +EXPOSE 8080 + +# Define the command to run your app using CMD which defines your runtime +CMD [ "npm", "start" ] \ No newline at end of file diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..525e29a --- /dev/null +++ b/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2024 Manthan Ankolekar + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/README.md b/README.md index e102aa5..9578cb4 100644 --- a/README.md +++ b/README.md @@ -1,16 +1,48 @@ # Learn Angular +This 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. +     - -## Contents + + + + + + + + + + + + +## Table of Contents - [Introduction](#introduction) + - [Features of Angular](#features-of-angular) + - [Difference between AngularJS vs Angular](#difference-between-angularjs-vs-angular) + - [Angular vs React](#angular-vs-react) - [Roadmap](#roadmap) - [Configuration](#configuration) + - [Prerequisites](#prerequisites) + - [Installation](#installation) - [Components](#components) + - [Three main building blocks](#three-main-building-blocks) + - [Component Creation](#component-creation) + - [Using Angular CLI](#using-angular-cli) + - [Manual Creation](#manual-creation) + - [Example](#example) + - [Scope](#scope) + - [View Encapsulation](#view-encapsulation) + - [Emulated View Encapsulation](#emulated-view-encapsulation) + - [Shadow DOM View Encapsulation](#shadow-dom-view-encapsulation) + - [None View Encapsulation](#none-view-encapsulation) + - [Component Communication](#component-communication) + - [Parent to Child](#parent-to-child) + - [Child to Parent](#child-to-parent) +- [Standalone Components](#standalone-components) - [Data Binding](#data-binding) - [One Way Binding](#one-way-binding) - [Two Way Binding](#two-ways-binding) @@ -19,6 +51,7 @@ - [Attribute Directives](#attribute-directives) - [Custom Directives](#custom-directives) - [Other Directives](#other-directives) +- [New Control Flow](#new-control-flow) - [Pipes](#pipes) - [Date Pipe](#date-pipe) - [Uppercase Pipe](#uppercase-pipe) @@ -35,6 +68,9 @@ - [HostListener](#hostlistener) - [ContentChild & ContentChildren](#contentchild--contentchildren) - [ViewChild & ViewChildren](#viewchild--viewchildren) + - [HostListener](#hostlistener) + - [ContentChild & ContentChildren](#contentchild--contentchildren) + - [ViewChild & ViewChildren](#viewchild--viewchildren) - [Life Cycle Hooks](#life-cycle-hooks) - [OnChanges](#onchanges) - [OnInit](#oninit) @@ -45,25 +81,88 @@ - [AfterContentChecked](#aftercontentchecked) - [OnDestroy](#ondestroy) - [Forms](#forms) -- [Signals](#signals) -- [Angular Signals](#angular-signals) + - [Template Driven Forms](#template-driven-forms) + - [Reactive Forms](#reactive-forms) +- [Services](#services) + - [Injectable Decorator](#injectable-decorator) + - [Dependency Injection](#dependency-injection) + - [Providers](#providers) +- [Routing](#routing) + - [Router Outlet](#router-outlet) + - [Router Link](#router-link) + - [Router Link Active](#router-link-active) + - [Router State](#router-state) + - [Router Events](#router-events) + - [Router Guards](#router-guards) +- [Lazy Loading](#lazy-loading) +- [HTTP Client](#http-client) - [Destroy Ref](#destroy-ref) - [Http](#http) - [Module](#module) - [Router](#router) - [Route Parameter](#route-parameters) +- [Route Guards](#route-guards) - [Observables](#observables-in-angular) + - [Creating Observables](#creating-observables) + - [Subscribing to Observables](#subscribing-to-observables) + - [Difference between Observables and Promises in Angular](#difference-between-observables-and-promises-in-angular) - [Unsubscribe](#unsubscribe-in-angular) - [Renderer2](#renderer2) -- [Standalone Components](#standalone-components) - [JIT](#jit) - [AOT](#aot) +- [Deferrable Views](#deferrable-views) - [Meta Tags](#meta-tags) - [Title Service](#title-service) - [Dynamic Title](#dynamic-title) - [Meta Service](#meta-service) +- [Angular Signals](#angular-signals) +- [Security](#security) + - [Preventing cross-site scripting (XSS)](#preventing-cross-site-scripting-xss) + - [Angular's cross-site scripting security model](#angulars-cross-site-scripting-security-model) + - [Preventing cross-site scripting (XSS)](#preventing-cross-site-scripting-xss) + - [Angular's cross-site scripting security model](#angulars-cross-site-scripting-security-model) + - [Sanitization and security contexts](#sanitization-and-security-contexts) + - [Sanitization example](#sanitization-example) + - [Direct use of the DOM APIs and explicit sanitization calls](#direct-use-of-the-dom-apis-and-explicit-sanitization-calls) + - [Trusting safe values](#trusting-safe-values) + - [Content security policy](#content-security-policy) + - [Enforcing Trusted Types](#enforcing-trusted-types) + - [Use the AOT template compiler](#use-the-aot-template-compiler) + - [Server-side XSS protection](#server-side-xss-protection) + - [HTTP-level vulnerabilities](#http-level-vulnerabilities) + - [Cross-site request forgery](#cross-site-request-forgery) + - [HttpClient XSRF/CSRF security](#httpclient-xsrfcsrf-security) + - [Configure custom cookie/header names](#configure-custom-cookieheader-names) + - [Disabling XSRF protection](#disabling-xsrf-protection) + - [Cross-site script inclusion (XSSI)](#cross-site-script-inclusion-xssi) + - [Auditing Angular applications](#auditing-angular-applications) +- [Angular Animations](#angular-animations) + - [Installing Angular Animations](#installing-angular-animations) +- [Angular Universal](#angular-universal) + - [Creating an Angular Universal application](#creating-an-angular-universal-application) +- [Bootstrap](#bootstrap) + - [Installing Bootstrap](#installing-bootstrap) + - [Importing Bootstrap](#importing-bootstrap) +- [Angular Material](#angular-material) + - [Installing Angular Material](#installing-angular-material) + - [Importing Angular Material](#importing-angular-material) +- [Tailwind CSS](#tailwind-css) + - [Installing Tailwind CSS](#installing-tailwind-css) + - [Importing Tailwind CSS](#importing-tailwind-css) +- [PrimeNG](#primeng) + - [Installing PrimeNG](#installing-primeng) + - [Importing PrimeNG](#importing-primeng) +- [SPA](#spa) + - [Advantages of SPA](#advantages-of-spa) +- [PWA](#pwa) + - [Installing PWA](#installing-pwa) + - [Configuring PWA](#configuring-pwa) + - [Building PWA](#building-pwa) + - [Service Worker](#service-worker) + - [Features of PWA](#features-of-pwa) - [CLI Commands](#cli-commands) - [Version compatibility](#version-compatibility) +- [Deploying an Angular Application](#deploying-an-angular-application) - [Imports](#imports) - [TypeScript](#typescript) - [RxJS](#rxjs) @@ -72,13 +171,29 @@ - [Learn From Books](#learn-more-from-books) - [Learn From YouTube Channels](#learn-from-youtube-channels) - [Learn More From Blogs Sites](#learn-more-from-blogs-sites) -- [List of Online Compilers/Editors](#list-of-online-editorscompiler) -- [List of Twitter Users](#list-of-twitter-users) -- [List of LinkedIn Users](#list-of-linkedin-users) +- [List of Online Editors/Compiler for Angular](#list-of-online-editorscompiler-for-angular) +- [List of Twitter Users to Follow](#list-of-twitter-users-to-follow) +- [List of LinkedIn Users to Follow](#list-of-linkedin-users-to-follow) +- [List of Discord Servers to Join](#list-of-discord-servers-to-join) ## Introduction -**Angular** is a platform and framework for building single-page client applications using HTML and TypeScript. +**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. + +### Features of Angular + +- **Component-Based Architecture**: Reusable, self-contained units of code that define the UI and behavior of a part of the application. +- **Two-Way Data Binding**: Automatic synchronization of data between the model and the view. +- **Dependency Injection**: Provides components with the services they need for better modularity and testability. +- **Routing**: Powerful system for navigation between different views, supporting deep linking, lazy loading, and route guards. +- **Forms**: Tools for template-driven and reactive forms, based on a model-driven approach. +- **HTTP Client**: Simple API for making HTTP requests and handling responses. +- **Observables**: Handles asynchronous operations and event handling. +- **TypeScript**: Superset of JavaScript with static typing, better tooling, error checking, and code completion. +- **Performance**: Optimized for performance with virtual DOM, lazy loading, tree shaking, and ahead-of-time compilation. +- **Mobile Support**: Tools for building responsive, touch-friendly mobile applications, including PWAs. +- **SEO Friendly**: Tools for server-side rendering, pre-rendering, and meta tags to improve search engine visibility. +- **Community Support**: Large, active community providing support and sharing knowledge. ### Difference between AngularJS vs Angular @@ -90,50 +205,193 @@ |Run on only client-side|Runs on both client-side as well as server-side| |CLI not present|CLI present| |No SEO Friendly|Seo Friendly| +|Performance is slow|Performance is fast| + +[Back to top⤴️](#table-of-contents) + +### Angular vs React + +- **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. + +- **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. + +**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. + +**When to use Angular**: Best for large, complex applications needing integrated tools and scalability. + +**When to use React**: Best for small to medium-sized applications needing flexibility and a focus on the UI. + +[Back to top⤴️](#table-of-contents) ## Roadmap -[https://roadmap.sh/angular](https://roadmap.sh/angular) +[Angular Roadmap](https://roadmap.sh/angular) ## Configuration ### Prerequisites - Node.js +- NPM +- Angular CLI ### Installation Install the Angular CLI globally: -```jsx +```bash npm install -g @angular/cli ``` +If you are using `pnpm`, you can use the following command: + +```bash +pnpm install -g @angular/cli +``` + +If you are using `yarn`, you can use the following command: + +```bash +yarn global add @angular/cli +``` + +If you are using `bun`, you can use the following command: + +```bash +bun install -g @angular/cli +``` + +If you want to install a specific version of the Angular CLI, you can use the following command: + +```bash +npm install -g @angular/cli@version-number +``` + +If you have already installed the Angular CLI, you can update it to the latest version using the following command: + +```bash +npm install -g @angular/cli@latest +``` + Check version -```jsx +```bash ng version ``` -Create workspace: +Create a new Angular project: (Replace `[PROJECT NAME]` with your project name) -```jsx +```bash +# with standalone component ng new [PROJECT NAME] + +# without standalone component +ng new [PROJECT NAME] --standalone=false + +## without routing +ng new [PROJECT NAME] --routing=false + +## without testing +ng new [PROJECT NAME] --skip-tests=true + +## without dependencies +ng new [PROJECT NAME] --skip-install=true + +## without git +ng new [PROJECT NAME] --skip-git=true + +## with experimental zonless +ng new [PROJECT NAME] --experimental-zoneless ``` -Run the application: +**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). + +Navigate to the project directory: -```jsx +```bash cd [PROJECT NAME] +``` + +Run the application: + +```bash ng serve ``` +Open the browser and navigate to `http://localhost:4200/`. + +Project structure(Version 16 and earlier): + +```bash +[PROJECT NAME] +├── node_modules +├── src +│ ├── app +│ │ ├── app.component.css +│ │ ├── app.component.html +│ │ ├── app.component.spec.ts +│ │ ├── app.component.ts +│ │ ├── app.module.ts +│ │ ├── ... +│ ├── assets +│ │ ├── .gitkeep +│ │ └── ... +│ ├── index.html +│ ├── main.ts +│ ├── styles.css +│ ├── favicon.ico +│ └── ... +├── .editorconfig +├── .gitignore +├── angular.json +├── package.json +├── README.md +├── tsconfig.json +├── tslint.json +└── ... +``` + +Project structure(Version 17 and later): + +```bash +[PROJECT NAME] +├── node_modules +├── public +│ ├── favicon.ico +│ └── ... +├── src +│ ├── app +│ │ ├── app.component.css +│ │ ├── app.component.html +│ │ ├── app.component.spec.ts +│ │ ├── app.component.ts +│ │ ├── app.config.ts +│ │ ├── app.routes.ts +│ │ └── ... +│ ├── index.html +│ ├── main.ts +│ ├── styles.css +│ └── ... +├── .editorconfig +├── .gitignore +├── angular.json +├── package.json +├── README.md +├── tsconfig.json +├── tslint.json +└── ... +``` + +[Back to top⤴️](#table-of-contents) + ## Components -Component is the main building block of an Angular Application. +Component 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. ### Three main building blocks +There are three main building blocks of an Angular component: + - Template - Class - Metadata @@ -146,6 +404,8 @@ Component is the main building block of an Angular Application. ### Component metadata properties +There are several properties that can be defined in the component metadata: + - Selector - Providers - Styles @@ -155,85 +415,167 @@ Component is the main building block of an Angular Application. **Selector** - Defines the element name or CSS selector that identifies the component in the HTML template. +```typescript +selector: 'app-root' +``` + **Providers** - Defines the providers of the component's dependencies. +```typescript +providers: [MyService] +``` + **styles** - Defines the inline styles for the component. +```typescript +styles: ['h1 { color: red; }'] +``` + **styleUrls** - Defines an array of URLs of the stylesheets for the component. +```typescript +styleUrls: ['./app.component.css'] +``` + **template** - Defines the HTML template for the component. +```typescript +template: '