Master Angular From Scratch

Learn Angular with clear, interactive, and structured lessons for beginners and developers.

ANGULAR COURSE SYLLABUS
1. Angular Introduction
Angular Introduction Angular History Angular Fundamentals Angular Architecture Component-Based Angular
2. Angular Setup
Angular Setup Introduction Installing Node.js Installing Angular CLI Creating an Angular Application Angular Project Structure
3. Components
Components Overview Component Anatomy Creating Components Component Selector Component Template Component Styles Component Metadata Standalone Components Parent and Child Components Reusable Components
4. Templates
Templates Introduction Template Syntax Template Expressions Template Statements Template Reference Variables ng-template ng-container ngTemplateOutlet Built-in Control Flow
5. Data Binding
Data Binding Introduction Interpolation Binding Property Binding Event Binding Two-Way Data Binding Class & Style Binding
6. Directives
Directives Introduction Attribute Directives Structural Directives Custom Directives
7. Pipes
Pipes Introduction Built-in Pipes Parameterized Pipes Chaining Pipes Custom Pipes
8. Event Handling
Event Handling Introduction DOM Events Event Binding Syntax Event Object Passing Data to Event Handlers
9. Input & Output
Component Communication @Input @Output EventEmitter
10. Lifecycle Hooks
Lifecycle Hooks Introduction ngOnInit ngOnChanges ngAfterViewInit ngOnDestroy
11. Services
Services Introduction Creating Angular Services Using Services in Components Sharing Data Through Services Service Scope
12. Dependency Injection
Dependency Injection Introduction Injecting Dependencies InjectionToken Provider Configuration
13. Routing
Routing Introduction Route Configuration RouterLink & Navigation Route Parameters Child Routes Route Guards
14. Forms
Angular Forms Introduction Template-Driven Forms Reactive Forms Form Validation Form Submission & Error Handling
15. HttpClient
HttpClient Introduction Configuring HttpClient GET Request POST, PUT & DELETE Requests Headers & Parameters HTTP Error Handling
16. Observables
Observables Introduction Creating & Subscribing to Observables Observable Data Streams Observable Operators Subscription Management
17. RxJS
RxJS Introduction RxJS Operators Transformation & Filtering Combining Observables Higher-Order Mapping Subjects
18. API Integration
API Integration Introduction Connecting Angular with REST API Consuming API Data CRUD API Integration API Response & Error Handling

Component Metadata

Angular Component Metadata defines how a component should behave, where its template is located, which styles it uses, and how Angular should identify and configure the component.

What is Component Metadata?

Component metadata is configuration information provided inside the Component decorator. It tells Angular important information about a component.

The metadata is written inside the @Component({ ... }) decorator.

Component Metadata Flow

Basic Component Metadata

A component commonly contains metadata such as selector, templateUrl and styleUrl.

student.component.ts
import { Component } from '@angular/core';

@Component({
    selector: 'app-student',
    templateUrl: './student.component.html',
    styleUrl: './student.component.css'
})
export class StudentComponent {

    studentName = 'Sam';

}

1. selector

The selector defines the custom HTML element used to display the component.

Selector
selector: 'app-student'

The component can then be used inside another template like this:

app.component.html
<app-student></app-student>
Result: Angular renders the StudentComponent wherever <app-student> is used.

2. templateUrl

The templateUrl property tells Angular where the component's external HTML template is located.

Component Metadata
templateUrl: './student.component.html'

Example template:

student.component.html
<h2>Student Details</h2>
<p>Student Name: {{ studentName }}</p>
Expected Output:

Student Details

Student Name: Sam

3. template

Instead of using a separate HTML file, a component can also define its HTML directly using the template property.

Inline Template
import { Component } from '@angular/core';

@Component({
    selector: 'app-student',
    template: `
        <h2>Student Details</h2>
        <p>Student Name: Sam</p>
    `
})
export class StudentComponent {

}
Expected Output:

Student Details

Student Name: Sam

4. styleUrl

The styleUrl property specifies the CSS file associated with the component.

Component Metadata
styleUrl: './student.component.css'
student.component.css
h2 {
    font-size: 26px;
    font-weight: 700;
}

p {
    font-size: 18px;
}

5. styles

The styles property allows CSS to be written directly inside the component metadata.

Inline Component Styles
@Component({
    selector: 'app-student',

    template: `
        <h2>Student Details</h2>
        <p>Student Name: Sam</p>
    `,

    styles: [`
        h2 {
            font-size: 26px;
        }

        p {
            font-size: 18px;
        }
    `]
})

6. standalone

Modern Angular applications commonly use standalone components. A standalone component can declare its own dependencies through the imports metadata property.

Standalone Component
import { Component } from '@angular/core';

@Component({
    selector: 'app-student',
    standalone: true,
    template: `
        <h2>Student Details</h2>
        <p>Student Name: Sam</p>
    `
})
export class StudentComponent {

}

7. imports

The imports metadata property is used by standalone components to make required Angular features or other standalone components/directives/pipes available to the template.

Example
@Component({
    selector: 'app-student',
    standalone: true,
    imports: [],
    template: `
        <h2>Student Details</h2>
    `
})

Important Metadata Properties

Complete Component Metadata Example

student.component.ts
import { Component } from '@angular/core';

@Component({
    selector: 'app-student',
    standalone: true,
    template: `
        <div class="student-card">
            <h2>Student Details</h2>
            <p>Student Name: Sam</p>
        </div>
    `,
    styles: [`
        .student-card {
            padding: 20px;
            border-radius: 8px;
        }

        h2 {
            margin-bottom: 10px;
        }
    `]
})
export class StudentComponent {

}
Expected Output:

Student Details

Student Name: Sam

Metadata Relationship

selector

How the component is placed in HTML.

template

What the component displays.

styles

How the component looks.

standalone

How the component is configured.

Complete Metadata Flow

@Component Metadata
↓
selector Component Identity
↓
template / templateUrl UI Structure
↓
styles / styleUrl UI Design
↓
Angular Rendered Component

Component Metadata Best Practices

  • Use clear and meaningful component selectors.
  • Keep large HTML templates in separate files.
  • Keep component-specific styles with the component.
  • Use standalone components for modern Angular applications when appropriate.
  • Keep metadata simple and easy to understand.
  • Use the imports property only for dependencies required by the template.

Summary

Component metadata provides Angular with the configuration required to create and render a component.

Important metadata properties include selector, template, templateUrl, styles, styleUrl, standalone and imports.

Understanding metadata is important because it connects the component class, template, styles and Angular configuration.