Angular Overview
Angular is a platform and framework for building single-page client applications using HTML and TypeScript. Angular is written in TypeScript. It implements core and optional functionality as a set of TypeScript libraries that you import into your applications.
Key Features
- Components: Building blocks of Angular applications.
- Templates: Define views with HTML and Angular template syntax.
- Dependency Injection: Makes components modular and reusable.
- Directives: Extend HTML with custom attributes and elements.
- Services: Reusable business logic components.
- RxJS: Powerful reactive programming library.
- CLI: Command-line interface for project scaffolding.
Common Use Cases
Enterprise Applications
Large-scale business applications with complex requirements.
Progressive Web Apps
Build installable, offline-capable web apps.
Single Page Applications
Dynamic web apps with smooth user experience.
Cross-Platform Apps
Using Ionic or NativeScript for mobile development.
Example Code
// Angular component example
import { Component } from '@angular/core';
@Component({
selector: 'app-greeter',
template: `
{{title}}
{{message}}
`,
styles: [`h2 { color: #369; }`]
})
export class GreeterComponent {
title = 'Greeting App';
name = '';
message = '';
greet() {
this.message = `Hello, ${this.name || 'stranger'}!`;
}
}
// Angular service example
import { Injectable } from '@angular/core';
import { HttpClient } from '@angular/common/http';
import { Observable } from 'rxjs';
@Injectable({
providedIn: 'root'
})
export class DataService {
constructor(private http: HttpClient) {}
getUsers(): Observable {
return this.http.get('https://api.example.com/users');
}
}