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 Styles

Component styles define the visual appearance of an Angular component. Angular allows styles to be associated with an individual component so that its user interface can be organized and maintained easily.

What are Component Styles?

Component styles are CSS rules associated with a specific Angular component. They control properties such as colors, fonts, spacing, borders and layout.

Simple Definition: Component Styles = CSS Rules + Component UI Appearance

Component Styling Flow

1
Component

Defines the Angular component.

→
2
CSS

Defines visual styles.

→
3
Angular

Associates styles with the component.

→
4
Browser

Displays the styled UI.

Basic Component with Styles

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';

}

The component is connected to its stylesheet using styleUrl.

Component CSS File

CSS rules can be written in the component stylesheet.

student.component.css
h2 {
    color: #4c1d95;
    font-size: 28px;
}

p {
    color: #475569;
    font-size: 18px;
}

HTML Template

student.component.html
<h2>
    Student Details
</h2>

<p>
    Student Name: {{ studentName }}
</p>

Expected Output

Student Details

Student Name: Sam

Inline Component Styles

For small components, styles can also be written directly inside the component metadata using the styles property.

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

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

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

    styles: [`
        h2 {
            color: #4c1d95;
        }

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

External Styles vs Inline Styles

External Styles
Inline Styles
CSS is stored in a separate file.
CSS is written inside the component.
Useful for larger components.
Useful for small components.
Easier to organize larger stylesheets.
Keeps a small component self-contained.

Common CSS Properties

A
Color
color

Changes text color.

B
Background
background

Changes background appearance.

T
Typography
font-size

Controls text size.

S
Spacing
margin / padding

Controls element spacing.

Styling HTML Classes

CSS classes can be created in the component stylesheet and applied to HTML elements.

student.component.css
.student-card {
    border: 1px solid #ddd6fe;
    padding: 20px;
    border-radius: 8px;
}

.student-name {
    color: #4c1d95;
    font-weight: 700;
}
student.component.html
<div class="student-card">

    <h2 class="student-name">
        Sam
    </h2>

</div>

Using styleUrl

The styleUrl property connects the component with its external stylesheet.

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

Component Style Scope

Angular component styles are associated with the component rather than simply being treated as one large application stylesheet.

Angular Application
│
HeaderComponent header styles
StudentComponent student styles
FooterComponent footer styles

Component Styling Best Practices

✓

Keep component-specific styles close to the component.

✓

Use meaningful CSS class names.

✓

Avoid unnecessary duplication of styles.

✓

Keep styles organized and easy to maintain.

Summary

Angular component styles control the visual appearance of a component.

Styles can be stored in an external CSS file using styleUrl or written directly using the styles property.

Keeping component styles organized makes Angular applications easier to maintain and understand.