Angular course Β· Module 1: Introduction to Angular

Angular Architecture

2 min read Β·
In this lesson2

Angular's architecture resembles the structure of feudal Japan - it is hierarchical, well-organized, and every element has its role.

Core Architectural Elements

1. Components (武士 - Bushi/Samurai)

Components are the heart of Angular - the basic UI unit, like a samurai in an army.

@Component({
  selector: 'app-samurai',
  standalone: true,
  template: `<div class="samurai">{{ name }}</div>`
})
export class SamuraiComponent {
  name = 'Musashi';
}

2. Modules (θ—© - Han/Clans)

Modules group related components, services, and other elements - like clans grouping samurai.

@NgModule({
  declarations: [],
  imports: [CommonModule],
  exports: []
})
export class SamuraiModule { }

Note: Since Angular 17+, Standalone Components without NgModules are preferred!

3. Services (職人 - Shokunin/Craftsmen)

Services contain business logic and are shared between components.

@Injectable({
  providedIn: 'root'
})
export class KatanaService {
  forge(): string {
    return 'A new katana has been forged!';
  }
}

providedIn: 'root' registers the service globally: Angular creates one instance for the whole application and hands it to every component that asks for it.

4. Directives (θ‘“ - Jutsu/Techniques)

Directives modify the behavior of DOM elements - like special combat techniques.

5. Pipes (ι€šθ¨³ - Tsuuyaku/Interpreters)

Pipes transform data in templates - like interpreters at the shogun's court.

Data Flow

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚              AppComponent               β”‚
β”‚  (Shogun - supreme commander)           β”‚
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”     β”‚
β”‚  β”‚ HeaderComp   β”‚  β”‚ SidebarComp  β”‚     β”‚
β”‚  β”‚ (General)    β”‚  β”‚ (Advisor)    β”‚     β”‚
β”‚  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜     β”‚
β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”   β”‚
β”‚  β”‚        MainContentComponent      β”‚   β”‚
β”‚  β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”   β”‚   β”‚
β”‚  β”‚  β”‚ ListComp   β”‚ β”‚ DetailComp β”‚   β”‚   β”‚
β”‚  β”‚  β”‚ (Squad)    β”‚ β”‚ (Samurai)  β”‚   β”‚   β”‚
β”‚  β”‚  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜   β”‚   β”‚
β”‚  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜   β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

Data flows top-down through @Input(), and events flow bottom-up through @Output() - like the shogun's orders and the samurai's reports.

Spotted a mistake in this lesson?

Check yourself

Answer the questions from this lesson. Pick an answer to see right away whether it is correct.

  1. 1. What is the basic UI unit in Angular?

  2. 2. Which decorator do we use to create services in Angular?

  3. 3. What are services used for in Angular?

  4. 4. With which decorator do we pass data down from a parent component to a child?

Hands-on tasks in the game

  • Horizontal ordering

    Arrange in one line the correct decorator that registers a service globally:

  • Vertical ordering

    Order the component tree from the diagram from the root (at the top) to the most deeply nested (at the bottom). Components on the same level can go in any order:

Useful articles