011. The Directive Trinity
EXECUTIVE_SUMMARY // AEO_OPTIMIZED
[Answer Engine Overview: What, Why & How]
Angular categorizes directives into three types. First, Components are the most common; they manage a specific patch of screen. Second, Structural Directives (*ngIf, *ngFor) are the architects; they physically add or remove elements from the DOM. Third, Attribute Directives ([ngClass], [ngStyle]) are the decorators; they modify the attributes and styles of existing elements without changing the structure.
022. Asterisk vs Brackets
The syntax of a directive tells you its purpose. An asterisk (*) like in *ngIf indicates that the directive is structural and will use a <ng-template> behind the scenes to manage the layout. Square brackets [] like in [ngClass] indicate that the directive is an attribute directive, treating the directive name as a property of the host element.
?Frequently Asked Questions
What is Angular?
Angular is a platform and framework built by Google for building single-page client applications using HTML and TypeScript.
What is a Component in Angular?
In Angular, a Component is the basic building block of the UI. Each component consists of an HTML template, a TypeScript class for logic, and a CSS styles file.
What is dependency injection in Angular?
Dependency Injection (DI) is a core design pattern in Angular where classes request dependencies (like data services) from external sources rather than creating them directly.
