Angular Architecture
Tags: angular7, angular
Published: 2020-07-15 09:34:53

---
title: Angular Architecture
published: true
date: 2019-12-18 22:03:56 UTC
tags: angular7,angular
canonical_url: 
---

![](https://cdn-images-1.medium.com/max/400/1*Fz8H1D6f5X5x926JN0yj_A.png)

Angular is one of the widely used frameworks for building SPA applications. Angular made writing the client-side applications more ease by adopting the TypeScript.

Below are the key components in Angular.

- Modules
- Components
- Templates
- Metadata
- Data Binding
- Directives
- Services
- Dependency Injection

### Module

In a general essence, the module is used to group the related classes together to achieve the functionality. The same definition is applicable for angular as well. In Angular, a module is a mechanism to group the related components, directives, pipes, services, etc together.

### Components

Components play a key role in Angular. Every Angular app must have at least one component.

> _In Angular, a component represents a specific portion of the user interface (UI)._

Each component will contain a selector that will represent the HTML associated with the component. To make a class a component, we need to add @Component({}), decorator.

### Templates

The template contains the HTML that needs to be displayed on the user screen. In Angular, the template contains the HTML elements and Angular custom tags/expressions as part of the template. Before projecting the template content, angular transform expressions, and custom tags will be replaced by the associated HTML.

> _In short, template is a combination of HTML tags + Angular Expressions + Custom tags defined using Angular_

### Metadata

In general, metadata termed as data about data. In Angular, metadata used to specify how a class needs to be processed by the Angular framework. A class decorator is used to define the metadata about the class. For example, any class that has @Component class decorator attached to it known as a Component.

> _Metadata defines how a class needs to be processed by the angular framework_

### Data Binding

Data binding concepts are used to bind the data from your component class to the template that is associated with the component. Below are the various way to bind the data to the view/template

**String Interpolation**  — represented as “`{{ }}`” also known as a mustache syntax. Angular process the expressions/variables insides the “`{{}}`” and insert the output into HTML.

**Property Binding**  — Allows binding the properties of an HTML element/Angular custom element.

**Event Binding**  — Allow the application to respond to user actions and inputs.

### Directives

> _Directives are used to add additional behavior to your HTML._

Here additional behavior may be altering the layout page by adding/deleting the HTML elements or additional functionality to your HTML element.

There are two types of Directives

**Structural directives** can alter the layout of the page by adding/removing the HTML elements. Structural directives prefix with ‘\*’

**Attribute directives** provide additional behavior or modify the appearance of your HTML elements.

### Services

In Angular, Services are singleton objects which get instantiated only once during the application lifetime. It contains data that needs to be shared across the application.

> _The primary objective of service is to organize and share the Business logic, and data with different components of an angular application._

### Dependency Injection

Dependency Injection is a process of injecting the dependent objects into a class from an external framework/ class. So that the class can focus on primary responsibility assigned to it. Dependency Injector will take of handling the lifetime of injected dependencies.

using dependency injection, we can externalize the injecting the dependencies to the classes and managing their lifetime.

![](https://cdn-images-1.medium.com/max/72/0*LNS11zVSxjKZ72oK.png)

_Originally published at_ [_http://www.techmonks.org_](http://www.techmonks.org/angular-architecture/) _on December 18, 2019._

* * *