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

Standalone Components

Standalone Components are Angular components that can work without being declared inside an NgModule. They provide a simpler and more direct way to organize modern Angular applications.

What is a Standalone Component?

A standalone component is a component configured with standalone: true. Its required dependencies can be imported directly through the component's imports property.

Simple Definition

A standalone component can manage its own template dependencies without requiring the component to be declared in an NgModule.

Traditional vs Standalone Components

Traditional Approach
  • Uses NgModules.
  • Components are declared in modules.
  • Dependencies are commonly configured at module level.
  • More configuration may be required.
Standalone Approach
  • Uses standalone: true.
  • No component declaration in an NgModule is required.
  • Dependencies can be imported directly.
  • Provides a simpler component structure.

Standalone Component Flow

User

Interacts with application

→
Standalone Component

Own configuration

→
Template

Displays UI

→
Browser

Rendered interface

Creating a Standalone Component

The following example creates a simple standalone component for displaying student information.

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

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

}
Expected Output:

Student Details

Student Name: Sam

The standalone Property

The standalone metadata property tells Angular that the component is standalone.

standalone: true
@Component({
    selector: 'app-student',
    standalone: true
})
Important

Standalone components manage their template dependencies directly instead of requiring component declaration through an NgModule.

Using the imports Property

Standalone components can specify the dependencies needed by their templates through the imports property.

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

}

When the template requires a standalone component, directive or pipe, the required item can be added to the imports array.

Standalone Component with External Template

A standalone component can also use an external HTML template.

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

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

    studentName = 'Pradnya';

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

Student Details

Student Name: Pradnya

Creating a Standalone Component Using CLI

Angular CLI can be used to generate components.

Angular CLI Command
ng generate component student

Short form:

Short CLI Command
ng g c student
ng Angular CLI
→
generate Create item
→
component Component type
→
student Component name

Standalone Component File Structure

Example Structure
student/
│
├── student.component.ts
├── student.component.html
├── student.component.css
└── student.component.spec.ts
student.component.ts

Contains component class and metadata.

student.component.html

Contains the component template.

student.component.css

Contains component-specific styles.

student.component.spec.ts

Contains component testing code.

Benefits of Standalone Components

Simpler Structure

Components can manage their own dependencies directly.

Less Configuration

Reduces the need for module-level component declarations.

Reusable

Standalone components can be imported where they are needed.

Clear Dependencies

Template dependencies can be visible in the component.

Complete Standalone Component Example

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

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

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

}
Expected Output:

Student Profile

Name: Sam

Course: Angular Full Stack

Complete Standalone Component Flow

@Component Component Metadata
↓
standalone: true Standalone Configuration
↓
imports Template Dependencies
↓
template User Interface
↓
Browser Rendered Component

Common Mistakes

❌ Forgetting standalone configuration

When creating a standalone component explicitly, make sure its configuration is correct.

❌ Missing template dependencies

If a template uses a standalone component, directive or pipe, the required dependency needs to be available to the component.

❌ Confusing component metadata with component logic

Metadata configures the component, while the component class contains its application logic.

Best Practices

  • Keep standalone components focused on a specific responsibility.
  • Keep component dependencies clear through the imports property.
  • Use meaningful selectors.
  • Keep templates readable and maintainable.
  • Keep component-specific styling close to the component.
  • Use reusable standalone components for common UI functionality.

Summary

Standalone Components are Angular components that can be configured independently without requiring component declaration inside an NgModule.

The standalone property enables standalone behavior, while the imports property provides dependencies required by the component template.

Standalone components help create a simpler, clearer and more modular Angular application structure.