Skip to content
geeksforgeeks
  • Tutorials
    • Python
    • Java
    • Data Structures & Algorithms
    • ML & Data Science
    • Interview Corner
    • Programming Languages
    • Web Development
    • CS Subjects
    • DevOps And Linux
    • School Learning
    • Practice Coding Problems
  • Courses
    • DSA to Development
    • Get IBM Certification
    • Newly Launched!
      • Master Django Framework
      • Become AWS Certified
    • For Working Professionals
      • Interview 101: DSA & System Design
      • Data Science Training Program
      • JAVA Backend Development (Live)
      • DevOps Engineering (LIVE)
      • Data Structures & Algorithms in Python
    • For Students
      • Placement Preparation Course
      • Data Science (Live)
      • Data Structure & Algorithm-Self Paced (C++/JAVA)
      • Master Competitive Programming (Live)
      • Full Stack Development with React & Node JS (Live)
    • Full Stack Development
    • Data Science Program
    • All Courses
  • AngularJS Tutorial
  • AngularJS Directives
  • AngularJS Functions
  • AngularJS Filters
  • AngularJS Examples
  • AngularJS Interview Questions
  • Angular ngx Bootstrap
  • AngularJS Cheat Sheet
  • AngularJS PrimeNG
  • JavaScript
  • Web Technology
Open In App
Next Article:
Explain the Architecture Overview of Angular ?
Next article icon

Explain the Architecture Overview of Angular ?

Last Updated : 28 Apr, 2025
Comments
Improve
Suggest changes
Like Article
Like
Report

Angular is a client-side front-end framework developed by a team of developers at Google based on Typescript. It is used for building dynamic and single-page web applications (SPAs). Also, Angular is a versatile framework for building web applications and offers a wide range of features and tools to streamline the development process and create robust and maintainable applications.

Angular Architecture Overview

To develop any web application, Angular follows the MVC (Model-View-Controller) and MVVM (Model-View-ViewModel) design patterns, which facilitates a structured and organized approach to designing the application, along with making it easier to manage code, improve maintainability, & etc. These types of design patterns usually maintain a clear distinction between data (Model), user interface (View), and logic (Controller/ViewModel), which results in more scalable and testable applications. It also provides code reusability and ensures a smoother development process for large & complex projects.

archi
Angular Architecture

An Angular Application contains the following building blocks:

Table of Content

  • Modules
  • Components
  • Templates
  • Directives
  • Services
  • Dependency Injection(DI)
  • Router
  • State Management
  • HTTP Client

We will explore the above topics & will understand their basic syntaxes.

Modules

  • A Module is a unit that consists of a separate block to perform specific functionality and enables us to break down the application into smaller chunks.
  • In a module, we can export & import the components and services from other modules.
  • Modules are created using the @NgModule decorator.
  • Types of Modules:
    • Core Module/Root Module
      • Every Angular application must have at least one root module, which is called the AppModule, defined in the app.module.ts file.
      • The root module is the top-level module in an Angular application.
      • It imports all of the other modules in the application.
    • Feature Module
      • Feature modules are used to group related components, directives, pipes, and services together.
    • Shared Module
      • The most commonly used functionality will be present in the shared module which can be imported by the feature module whenever needed.

Example: app.module.ts

JavaScript
import { NgModule } from '@angular/core'; import { BrowserModule }      from '@angular/platform-browser';  import { AppRoutingModule }     from './app-routing.module'; import { AppComponent } from './app.component';  @NgModule({     declarations: [         AppComponent     ],     imports: [         BrowserModule,         AppRoutingModule     ],     providers: [],     bootstrap: [AppComponent] }) export class AppModule { } 

Components

  • A Component is the building block of the angular application.
  • A component consists of a template(HTML view of UI), styles(CSS appearance/design) and a typescript class which contains business logic.
  • To indicate a class as component @Component decorator is used.
  • The @Component decorator provides metadata to the component.
  • The component metadata properties consist of selectors, directives, providers, styleUrls and templateUrls.

Example: app.component.ts

JavaScript
import { Component } from '@angular/core';  @Component({     selector: 'app-root',     templateUrl: './app.component.html',     styleUrls: ['./app.component.css'] }) export class AppComponent {     title = 'AngularApp'; } 

Templates

  • The user interface or the view of the end users is defined using the template.
  • Templates are created using HTML and it binds the component properties and methods thus helping us to render data dynamically.
  • Template syntax includes directives, interpolation, built-in directives, template expression operators, property binding, and event binding for creating dynamic and interactive views.

Example: app.component.html

HTML
<h2>Welcome to GeeksForGeeks</h2>  <p>Angular Architecture consists of :</p> <ul>     <li>Modules</li>     <li>Components</li>     <li>Templates</li>     <li>Directives</li>     <li>Services</li>     <li>Dependency Injection(DI)</li>     <li>Router</li>     <li>HTTP Client</li>     <li>State Management</li> </ul> 

Directives

  • Directives are instructions in the DOM (Document Object Model).
  • Directives are used in templates to customize the behaviour of the elements.
  • Angular provides built-in directives like *ngIf and *ngFor, as well as custom directives created by developers.
  • Types of directives:
    • Component Directives
      • These directives are associated with the template(view) of a component.
    • Structural Directives
      • These directives are used to change the structure of the DOM using *ngFor,*ngSwitch and *ngIf.
    • Attribute Directives
      • These directives are used to change the behaviour of the DOM using ngStyle,ngModel and ngClass.
    • Custom Directives
      • We can create custom directives using @Directive decorator and define the desired behaviour in the class.

Example:

  • app.component.html
HTML
<!--  Structural Directive: ngIf,ngFor,ngSwitch --> <div class='card'>     <p>ngSwitch Example</p>     <div class="card-body">         Input string :            <input type='text' [(ngModel)]="num" />         <div [ngSwitch]="num">             <div *ngSwitchCase="'1'">One</div>             <div *ngSwitchCase="'2'">Two</div>             <div *ngSwitchCase="'3'">Three</div>             <div *ngSwitchCase="'4'">Four</div>             <div *ngSwitchCase="'5'">Five</div>             <div *ngSwitchDefault>This is Default</div>         </div>     </div>     <div>         <p>ngFor and ngIf Example</p>         <div *ngFor="let emp of employee">             <ng-container *ngIf="emp.age>=30">                 <p>{{ emp.name }}: {{ emp.age }}</p>             </ng-container>         </div>         <div><!-- Attribute Directive: [ngStyle] -->             <p [ngStyle]=                "{'color': 'blue', 'font-size': 12}">                   ngStyle Example               </p>         </div>                  <!-- Custom Directive: ng g directive uppercase -->         <div>             <input type="text" appUppercase                     placeholder="Enter text" />         </div>     </div> </div> 
  • app.component.ts
JavaScript
import { Component } from '@angular/core';  @Component({     selector: 'app-root',     templateUrl: './app.component.html',     styleUrls: ['./app.component.css'] }) export class AppComponent {     title = 'AngularApp';     num: number = 0;     employee: Employee[] = [          { name: 'Emp1', age: 30 },         { name: 'Emp2', age: 37 },         { name: 'Emp3', age: 26 },      ] } class Employee {      name: string;     age: number;  } 
  • uppercase.directive.ts
JavaScript
import { Directive,           ElementRef,           HostListener,           Renderer2 }      from '@angular/core';  @Directive({     selector: '[appUppercase]' }) export class UppercaseDirective {      constructor(private el: ElementRef,                  private renderer: Renderer2) { }      @HostListener('input', ['$event']) onInputChange(event: Event) {         const inputValue =              (event.target as HTMLInputElement).value;         const newValue =              inputValue.toUpperCase();         this.renderer.setProperty(this.el.nativeElement, 'value', newValue);     } } 

Services

  • Services are used when specific data or logic needs to be used across different components.
  • Services are typically used to centralize data access, HTTP requests, state management, and other common tasks.
  • Services are singleton and are registered with Angular's dependency injection system.
  • Components can inject services to access their functionality and data.
  • command to create:
ng generate service counter

Example: counter.service.ts

JavaScript
import { Injectable } from '@angular/core';  @Injectable({     providedIn: 'root', }) export class CounterService {     private count = 0;      increment(): void {         this.count++;     }      getCount(): number {         return this.count;     } } 

Dependency Injection(DI)

  • Dependency injection simplifies dependency management, facilitates code reusability and simplifies testing.
  • DI is a design pattern which increases the flexibility and modularity of the applications by producing and distributing specific parts of the application to other parts of the application that need them.
  • We can inject services, configuration values, and other objects into components and services.
  • Components and services can declare their dependencies and have them injected automatically using @Injectable decorator.

Router

  • The Angular Router manages navigation within the application for changing from one view to another view.
  • Routes are defined in the app-routing.module.ts file and map to specific components.
  • The router also supports route parameters, route guards, and child routes for creating complex navigation structures.

Example: app-routing.module.ts

JavaScript
import { NgModule } from '@angular/core'; import { Routes, RouterModule }      from '@angular/router'; import { EmployeeListComponent }      from './employee-list/employee-list.component'; import { CreateEmployeeComponent }      from './create-employee/create-employee.component'; import { UpdateEmployeeComponent }      from './update-employee/update-employee.component'; import { EmployeeDetailsComponent }      from './employee-details/employee-details.component';  const routes: Routes = [     { path: 'employees',        component: EmployeeListComponent },     { path: 'create-employee',        component: CreateEmployeeComponent },     { path: '', redirectTo: 'employees',        pathMatch: 'full' },     { path: 'update-employee/:id',       component: UpdateEmployeeComponent },     { path: 'employee-details/:id',        component: EmployeeDetailsComponent } ];  @NgModule({     imports: [RouterModule.forRoot(routes)],     exports: [RouterModule] }) export class AppRoutingModule { } 

State Management

  • State management in angular is achieved using RxJS (Reactive Extensions for JavaScript).
  • RxJS is used for handling asynchronous operations, such as handling HTTP requests, user interactions, and event-driven programming.
  • Streams of data and events are managed by Observables which is provided by RxJS.

HTTP Client

  • HTTP client module in angular is used for making HTTP requests to interact with backend services(API calls) to fetch or send data.

Example: post-list.component.ts

JavaScript
import { Component, OnInit }      from '@angular/core'; import { HttpClient }      from '@angular/common/http';  @Component({     selector: 'app-post-list',     templateUrl: './post-list.component.html',     styleUrls: ['./post-list.component.css'], }) export class PostListComponent implements OnInit {     posts: any[] = [];      constructor(private http: HttpClient) { }      ngOnInit(): void {         this.http             .get < any[] > (             'https://jsonplaceholder.typicode.com/posts')                 .subscribe((data) => {                     this.posts = data;                 });     } } 

Next Article
Explain the Architecture Overview of Angular ?

J

julietmaria
Improve
Article Tags :
  • Web Technologies
  • AngularJS
  • Geeks Premier League
  • AngularJS-Questions
  • Geeks Premier League 2023

Similar Reads

    Explain AngularJS Scope Life-Cycle
    In AngularJS, The Scope acts as a merging parameter between the HTML and Javascript code, ie, it is the binding part between view and controller and it is a built-in object. It is available for both the view and the controller. It is used to define inside the controller, in order to define the membe
    8 min read
    Explain the purpose of Router services in Angular.
    The Router service in Angular is an important component that enables navigation within our single-page application (SPA). It involves mapping URLs to different components or views within the application and rendering the appropriate content based on the requested URL. When a user interacts with navi
    6 min read
    Angular 7 | Architecture
    Angular is a platform or framework to build client-based applications in HTML and TypeScript. It is written in TypeScript. It implements core and optional functionality as a set of TypeScript libraries that are imported into applications. Angular consists of Three main things that are Modules, Compo
    5 min read
    Architecture of a System
    Architecture is a critical aspect of designing a system, as it sets the foundation for how the system will function and be built. It is the process of making high-level decisions about the organization of a system, including the selection of hardware and software components, the design of interfaces
    4 min read
    Purpose of the FormsModule in Angular
    Forms are widely used in web applications that allow you to provide the data, submit the forms, and interact with the application. In Angular for handling the forms, we use Forms Module which imports several powerful tools for creating, managing, and validating forms. In this article, we'll cover th
    5 min read
geeksforgeeks-footer-logo
Corporate & Communications Address:
A-143, 7th Floor, Sovereign Corporate Tower, Sector- 136, Noida, Uttar Pradesh (201305)
Registered Address:
K 061, Tower K, Gulshan Vivante Apartment, Sector 137, Noida, Gautam Buddh Nagar, Uttar Pradesh, 201305
GFG App on Play Store GFG App on App Store
Advertise with us
  • Company
  • About Us
  • Legal
  • Privacy Policy
  • In Media
  • Contact Us
  • Advertise with us
  • GFG Corporate Solution
  • Placement Training Program
  • Languages
  • Python
  • Java
  • C++
  • PHP
  • GoLang
  • SQL
  • R Language
  • Android Tutorial
  • Tutorials Archive
  • DSA
  • Data Structures
  • Algorithms
  • DSA for Beginners
  • Basic DSA Problems
  • DSA Roadmap
  • Top 100 DSA Interview Problems
  • DSA Roadmap by Sandeep Jain
  • All Cheat Sheets
  • Data Science & ML
  • Data Science With Python
  • Data Science For Beginner
  • Machine Learning
  • ML Maths
  • Data Visualisation
  • Pandas
  • NumPy
  • NLP
  • Deep Learning
  • Web Technologies
  • HTML
  • CSS
  • JavaScript
  • TypeScript
  • ReactJS
  • NextJS
  • Bootstrap
  • Web Design
  • Python Tutorial
  • Python Programming Examples
  • Python Projects
  • Python Tkinter
  • Python Web Scraping
  • OpenCV Tutorial
  • Python Interview Question
  • Django
  • Computer Science
  • Operating Systems
  • Computer Network
  • Database Management System
  • Software Engineering
  • Digital Logic Design
  • Engineering Maths
  • Software Development
  • Software Testing
  • DevOps
  • Git
  • Linux
  • AWS
  • Docker
  • Kubernetes
  • Azure
  • GCP
  • DevOps Roadmap
  • System Design
  • High Level Design
  • Low Level Design
  • UML Diagrams
  • Interview Guide
  • Design Patterns
  • OOAD
  • System Design Bootcamp
  • Interview Questions
  • Inteview Preparation
  • Competitive Programming
  • Top DS or Algo for CP
  • Company-Wise Recruitment Process
  • Company-Wise Preparation
  • Aptitude Preparation
  • Puzzles
  • School Subjects
  • Mathematics
  • Physics
  • Chemistry
  • Biology
  • Social Science
  • English Grammar
  • Commerce
  • World GK
  • GeeksforGeeks Videos
  • DSA
  • Python
  • Java
  • C++
  • Web Development
  • Data Science
  • CS Subjects
@GeeksforGeeks, Sanchhaya Education Private Limited, All rights reserved
We use cookies to ensure you have the best browsing experience on our website. By using our site, you acknowledge that you have read and understood our Cookie Policy & Privacy Policy
Lightbox
Improvement
Suggest Changes
Help us improve. Share your suggestions to enhance the article. Contribute your expertise and make a difference in the GeeksforGeeks portal.
geeksforgeeks-suggest-icon
Create Improvement
Enhance the article with your expertise. Contribute to the GeeksforGeeks community and help create better learning resources for all.
geeksforgeeks-improvement-icon
Suggest Changes
min 4 words, max Words Limit:1000

Thank You!

Your suggestions are valuable to us.

What kind of Experience do you want to share?

Interview Experiences
Admission Experiences
Career Journeys
Work Experiences
Campus Experiences
Competitive Exam Experiences