Angular's architecture resembles the structure of feudal Japan - it is hierarchical, well-organized, and every element has its role.
Components are the heart of Angular - the basic UI unit, like a samurai in an army.
1@Component({
2 selector: 'app-samurai',
3 standalone: true,
4 template: \`<div class="samurai">{{ name }}</div>\`
5})
6export class SamuraiComponent {
7 name = 'Musashi';
8}Modules group related components, services, and other elements - like clans grouping samurai.
1@NgModule({
2 declarations: [],
3 imports: [CommonModule],
4 exports: []
5})
6export class SamuraiModule { }Note: Since Angular 17+, Standalone Components without NgModules are preferred!
Services contain business logic and are shared between components.
1@Injectable({
2 providedIn: 'root'
3})
4export class KatanaService {
5 forge(): string {
6 return 'A new katana has been forged!';
7 }
8}Directives modify the behavior of DOM elements - like special combat techniques.
Pipes transform data in templates - like interpreters at the shogun's court.
1βββββββββββββββββββββββββββββββββββββββββββ
2β AppComponent β
3β (Shogun - supreme commander) β
4βββββββββββββββββββββββββββββββββββββββββββ€
5β ββββββββββββββββ ββββββββββββββββ β
6β β HeaderComp β β SidebarComp β β
7β β (General) β β (Advisor) β β
8β ββββββββββββββββ ββββββββββββββββ β
9β ββββββββββββββββββββββββββββββββββββ β
10β β MainContentComponent β β
11β β ββββββββββββββ ββββββββββββββ β β
12β β β ListComp β β DetailComp β β β
13β β β (Squad) β β (Samurai) β β β
14β β ββββββββββββββ ββββββββββββββ β β
15β ββββββββββββββββββββββββββββββββββββ β
16βββββββββββββββββββββββββββββββββββββββββββData flows top-down through @Input(), and events flow bottom-up through @Output() - like the shogun's orders and the samurai's reports.