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

Angular Component Selector

A component selector defines the HTML element, attribute or pattern that Angular uses to identify and display a component.

What is a Component Selector?

The selector is a property inside the @Component decorator. It tells Angular how the component should be used inside another HTML template.

Simple Definition: Selector = Identifies where the component is used

Basic Selector Example

Consider a Student component with the following selector:

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

@Component({
    selector: 'app-student'
})
export class StudentComponent {

    studentName = 'Sam';

}

The selector is:

app-student

1. Element Selector

The most common selector type is an element selector. It allows the component to be used as a custom HTML element.

Component
@Component({
    selector: 'app-student'
})

Use the component in an HTML template:

HTML Template
<app-student></app-student>
Result

Angular renders the StudentComponent wherever <app-student> is used.

2. Attribute Selector

A component can also use an attribute selector. In this case, the component is applied through an HTML attribute.

Component
@Component({
    selector: '[app-student]'
})
export class StudentComponent {
}

The selector can then be used as an attribute:

HTML
<div app-student></div>
Important

Attribute selectors are useful when a component or directive needs to be identified through an HTML attribute.

3. Class Selector

A selector can also be defined using a CSS class pattern.

Component
@Component({
    selector: '.student-card'
})
export class StudentComponent {
}

It can then be referenced using the class name:

HTML
<div class="student-card"></div>

Selector Types

E
Element
app-student

Used as a custom HTML element.

A
Attribute
[app-student]

Used as an HTML attribute.

C
Class
.student-card

Identifies an element through a class selector.

How Selector Works

1
Define Selector

Selector is defined in @Component.

→
2
Use Selector

Selector is placed in HTML.

→
3
Angular Matches

Angular finds the matching element.

→
4
Component Rendered

Angular displays the component.

Practical Example

Let's create a Student component and use its selector inside the application.

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

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

Use the component in the parent template:

app.component.html
<h1>CIIT Student Management</h1>

<app-student></app-student>

Expected Output

CIIT Student Management


Student Details

Student Name: Sam

Selector Naming Convention

Angular projects commonly use a prefix in component selectors. This helps avoid conflicts with existing HTML elements.

Examples
app-student
app-header
app-footer
app-dashboard
app-student-list
Recommended: Use clear and meaningful selector names.

Selector vs Component Name

Component Name
Selector
StudentComponent
app-student
HeaderComponent
app-header
FooterComponent
app-footer

Common Selector Mistakes

1. Incorrect selector

Make sure the selector used in the HTML matches the selector defined in the component.

2. Missing component availability

The component must be available in the Angular context where the selector is used.

3. Confusing class and element selectors

Use the correct syntax according to the selector defined in the component.

Summary

A component selector tells Angular how a component is identified and used in an HTML template.

The most common approach is an element selector such as app-student.

Selectors should be meaningful and consistently named throughout the Angular application.