Angular Introduction
Angular is a complete framework for building web applications with TypeScript.
What is Angular?
- Angular is an open-source framework made and maintained by Google
- It is written in TypeScript
- It is a full platform: components, routing, forms, HTTP and testing are included
- A new major version comes out about every six months
React is a library that you combine with other tools. Angular is a framework that already includes most of what a large app needs. This means more to learn at the start, but fewer decisions later.
Angular vs AngularJS
The names are confusing, so let us be clear:
| AngularJS | Angular | |
|---|---|---|
| Version | 1.x | 2 and later (today 20+) |
| Language | JavaScript | TypeScript |
| Released | 2010 | 2016 |
| Status | No longer supported since 2022 | Actively developed |
They are different frameworks. Code written for one does not run in the other. This tutorial teaches modern Angular.
Building Blocks of an Angular App
| Building block | What it does |
|---|---|
| Component | A piece of the screen: a TypeScript class plus an HTML template |
| Template | The HTML of a component, with Angular syntax for data and events |
| Signal | A reactive value; when it changes, the screen updates |
| Service | A class for shared logic, such as loading data |
| Router | Shows different components for different URLs |
A Component Example
Example
import { Component } from "@angular/core";
@Component({
selector: "app-welcome",
template: `<h2>Welcome to {{ institute }}</h2>
<p>Location: {{ city }}</p>`,
})
export class Welcome {
institute = "Workownix";
city = "Karachi";
}Welcome to Workownix Location: Karachi
@Componentis a decorator. It tells Angular that this class is a componentselectoris the HTML tag name. You use it as<app-welcome />templateis the HTML.{{ }}shows values from the class
What is New in Modern Angular
Angular has changed a lot in recent versions. If you read older tutorials, you will see differences:
- Standalone components are the default. Older apps put every component inside an
NgModule - Signals give simple, fine-grained reactivity
- Built-in control flow (
@if,@for,@switch) replaces*ngIfand*ngFor - `inject()` is a simple way to get services
- New projects do not need
zone.js, so apps are lighter and faster
When you look for help online, check the Angular version. Answers written for Angular 8 or 12 often use older patterns.
What You Should Know First
- HTML and CSS
- JavaScript: functions, arrays, objects, classes and modules
- Basic TypeScript: types like
string,numberand interfaces
TypeScript example:
Example
interface Student {
name: string;
marks: number;
}
const ali: Student = { name: "Ali", marks: 88 };
console.log(`${ali.name} scored ${ali.marks}`);Ali scored 88
Exercise
Exercise
What is the relationship between AngularJS and Angular?
