Introduction & Setup: Welcome to Angular
6 min read
Course: Angular
Topic: Introduction & Setup: Welcome to Angular
π Welcome to the Platform
Welcome to the start of your journey with Angular. If you have been wandering in the wilderness of "just a library" solutions where you have to glue together a router, a form validator, and a state manager with duct tape, you have found a home.
Angular is not just a framework; it is a Platform.
In this guide, we will move from zero to a running application, covering the philosophy, the tools, and the anatomy of a modern Angular project.
1. The Angular Ecosystem: Why Choose Angular?
π§ Definition
Angular is a component-based web framework for building scalable web applications. It is a collection of well-integrated libraries that cover a wide variety of features, including routing, forms management, client-server communication, and more.
π« The Problem
Imagine you are building a massive skyscraper (a complex enterprise app).
- In other ecosystems: You are given a hammer and a saw. You have to go to the store to buy your own blueprints, your own cement mixer, and your own safety gear. If the cement mixer doesn't fit the blueprints you bought, that's your problem.
- The Spaghetti Result: As apps grow, without strict standards, developers tend to invent their own "style," leading to codebases that look like a plate of spaghetti dropped on the floor.
π‘ The Solution
Angular provides the Blueprint and the Heavy Machinery.
- Opinionated: It tells you where to put your files and how to write your code. This sounds strict, but it means a developer from Team A can join Team B and instantly understand the code.
- Batteries-Included: Routing (
@angular/router), Forms (@angular/forms), and HTTP clients (@angular/common/http) are all official, updated together, and guaranteed to work together. - Evergreen: The Angular team at Google updates the framework every 6 months. With automated update tools (
ng update), you never get stuck on "legacy" code for long.
ποΈ Peace of Mind: You don't spend weekends debating which Router library is "trending" this week. You just use the Angular Router. It works. It allows you to focus on business logic, not glue logic.
π§ Interesting Fact
Angular (v2+) was a complete rewrite of the old AngularJS (v1). It was such a drastic change that for a while, people called it "Angular 2". Now, we just call it "Angular."
- Modern Era (v17+): Angular recently underwent a "Renaissance." It ditched the heavy "Modules" (NgModule) system for Standalone Components and adopted Signals for fine-grained reactivity, making it faster and lighter than ever before.
2. Setting Up Your Environment (Node.js & Angular CLI)
Before we can build, we need our tools. Angular relies on Node.js to run its build tools and manage dependencies.
π οΈ Prerequisites
- Node.js: You need an active LTS (Long Term Support) version. As of 2026, you should be using Node v20 or newer.
- Check if you have it: Run
node -vin your terminal. - Get it: Download from nodejs.org.
- Check if you have it: Run
- Package Manager: Node comes with
npm, which we will use to install the Angular CLI.
π» Installing the CLI
The Angular CLI (Command Line Interface) is your best friend. It creates projects, generates code, and runs tests. It is the "magic wand" of the Angular ecosystem.
Open your terminal or command prompt and run:
npm install -g @angular/clinpm: Node Package Manager.install: The command to download software.-g: Global flag. We want the CLI available everywhere on your computer, not just in one folder.@angular/cli: The official package name.
β οΈ Industry Standard: serious developers often use nvm (Node Version Manager) to install Node.js. This allows you to switch between Node versions for different projects easily without permission errors.
3. Creating Your First App: ng new and ng serve
Now that we have the wand, let's cast the spell.
β‘ generating the Project
Navigate to the folder where you keep your coding projects and run:
ng new my-dream-appThe CLI will ask you a few questions. Here is how to answer them for a standard modern setup:
- Which stylesheet format would you like to use?
- Select
SCSS(Sass) orCSS. Sass is the industry standard for easier styling.
- Select
- Do you want to enable Server-Side Rendering (SSR) and Static Site Generation (SSG/Prerendering)?
- For this beginner course, you can say No (N) to keep it simple. However, in production, Angular's SSR (Hydration) is incredibly powerful for SEO.
Imagine the CLI as a construction crew: It is currently downloading thousands of tiny packages, setting up a testing framework, configuring the build system (Vite/Esbuild), and initializing Git for you.
π Serving the Application
Once the installation finishes (you see a "Packages installed successfully" message), enter your project folder:
cd my-dream-app
ng serveng serve: Compiles your code in memory and launches a local web server.- Open your browser and go to
http://localhost:4200.
π Congratulations! You are looking at a running Angular application. It supports Hot Module Replacement (HMR)βtry changing some text in the code, hit save, and watch the browser update instantly without reloading the page.
4. Tour of the Workspace: Understanding Project Structure
Angular projects used to be famous for having many files. Modern Angular (Standalone) is much cleaner, but every file has a specific purpose.
Let's look at the anatomy of my-dream-app:
π Root Level
angular.json: The Architect. This file contains the configuration for the CLI. It tells Angular how to build, test, and serve your app.package.json: The Manifest. Lists all the libraries your app depends on (like RxJS, TypeScript, Angular Core).tsconfig.json: The Translator rules. Configures how TypeScript should be converted into JavaScript that browsers understand.
π The src Folder (Where you live)
main.ts: The Ignition Key.- This is the entry point of your application.
- It uses
bootstrapApplicationto start the app. - It loads
app.config.ts.
index.html: The Canvas.- This is the only HTML file served by the server (Single Page Application).
- Body usually contains just one tag:
<app-root></app-root>.
styles.scss: Global styles that apply to the whole app.
π The src/app Folder (Your Code)
In modern Angular, we don't use AppModule anymore. We use a cleaner setup:
app.config.ts:- Concept: Global Configuration.
- Purpose: This replaces the old
app.module.ts. Here you provide global services like the Router, HTTP Client, or Animations. - Example:
provideRouter(routes)lives here.
app.routes.ts:- Concept: The Map.
- Purpose: Defines which component shows up when the URL changes (e.g.,
/home-> HomeComponent).
app.component.ts:- Concept: The Root Component.
- Purpose: The mother of all components. Every other component you build will be nested inside this one.
- Key Feature: Look for
standalone: truein the metadata. This is the modern standard.
πΌοΈ Visualization: The Component Tree
Think of your app like a tree.
AppComponentis the Trunk.HeaderComponentandFooterComponentare big branches.ButtonComponentis a leaf.
The Magic: In Angular, you define a component once (the definition), and you can plant that tree anywhere using its selector (e.g., <app-button>).
π References & Further Reading
- Official Documentation (The Bible): angular.dev
- CLI Command Reference: angular.dev/cli
- Node.js Download: nodejs.org
Now that the environment is ready, we are prepared to start building actual components in the next guide. Keep your terminal open! π»
Challenge
You are tasked with manually setting up the core files for a modern, standalone Angular application. In the editor below, write the complete TypeScript code for two essential files: main.ts and app.component.ts.
Requirements:
main.ts:- This file must handle the application's bootstrap process.
- Import
bootstrapApplicationfrom@angular/platform-browser. - Import the root component,
AppComponent. - Call
bootstrapApplicationto start the app, passing the root component.
app.component.ts:- This file must define the root
AppComponent. - It must be configured as a
standalonecomponent. - Its CSS selector must be
app-root. - Its template must be an inline
<h1>tag containing the textWelcome to Angular!.
- This file must define the root
Use comments // FILENAME: main.ts and // FILENAME: app.component.ts to clearly separate the code for each file within the editor.
Expected result
Your submission should contain the complete TypeScript code for both main.ts and app.component.ts, separated by comments as specified.
main.ts should contain:
import { bootstrapApplication } from '@angular/platform-browser';
import { AppComponent } from './app.component';
bootstrapApplication(AppComponent)
.catch((err) => console.error(err));app.component.ts should contain:
import { Component } from '@angular/core';
@Component({
selector: 'app-root',
standalone: true,
imports: [],
template: '<h1>Welcome to Angular!</h1>',
styles: []
})
export class AppComponent {}