Angular 3 does not exist as an official version. Google skipped version 3 to align the Angular package versions, jumping directly from Angular 2 to Angular 4. However, the concepts from Angular 2 and later versions are relevant to understanding the basics of Angular’s modern framework. This guide focuses on Angular basics with examples applicable to Angular 2+ versions.
Key Features of Angular Framework
Component-Based Architecture Angular uses components to define views and logic, making applications modular and maintainable.
Modules Angular applications are divided into modules (NgModules), organizing code into cohesive blocks.
Templates Templates define the HTML structure and are linked to logic with Angular syntax.
Directives Angular directives dynamically manipulate the DOM and extend HTML functionality.
Two-Way Data Binding Angular synchronizes the UI and the data model seamlessly.
Services and Dependency Injection (DI) Angular uses services for reusable business logic and DI to inject dependencies into components.
Routing Angular Router provides navigation between different views in a single-page application.
Basic Angular 3 Building Blocks
Modules Modules are containers for components, directives, pipes, and services.
Example:
typescript
import { NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { AppComponent } from './app.component';
@NgModule({
declarations: [AppComponent],
imports: [BrowserModule],
bootstrap: [AppComponent],
})
export class AppModule {}
Components Components are the heart of Angular applications, defining templates and logic.
Example:
typescript
import { Component } from '@angular/core';
@Component({
selector: 'app-root',
template: '<h1>{{ title }}</h1>',
styles: ['h1 { color: green; }'],
})
export class AppComponent {
title = 'Welcome to Angular!';
}
Templates Templates bind data from the component logic to the UI.
Example:
html
<h1>{{ title }}</h1>
<button (click)="changeTitle()">Change Title</button>
Component Logic:
typescript
changeTitle() {
this.title = 'Title Updated!';
}
Directives Angular includes structural (*ngIf, *ngFor) and attribute (ngClass, ngStyle) directives.
Example - Structural Directive:
html
<div *ngIf="showContent">Content is visible!</div>