Learn Angular Β· 1/14

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

  1. 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 -v in your terminal.
    • Get it: Download from nodejs.org.
  2. 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:

bash
npm install -g @angular/cli
  • npm: 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:

bash
ng new my-dream-app

The CLI will ask you a few questions. Here is how to answer them for a standard modern setup:

  1. Which stylesheet format would you like to use?
    • Select SCSS (Sass) or CSS. Sass is the industry standard for easier styling.
  2. 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:

bash
cd my-dream-app
ng serve
  • ng 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 bootstrapApplication to 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:

  1. 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.
  2. app.routes.ts:
    • Concept: The Map.
    • Purpose: Defines which component shows up when the URL changes (e.g., /home -> HomeComponent).
  3. 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: true in the metadata. This is the modern standard.

πŸ–ΌοΈ Visualization: The Component Tree

Think of your app like a tree.

  • AppComponent is the Trunk.
  • HeaderComponent and FooterComponent are big branches.
  • ButtonComponent is 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

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:

  1. main.ts:

    • This file must handle the application's bootstrap process.
    • Import bootstrapApplication from @angular/platform-browser.
    • Import the root component, AppComponent.
    • Call bootstrapApplication to start the app, passing the root component.
  2. app.component.ts:

    • This file must define the root AppComponent.
    • It must be configured as a standalone component.
    • Its CSS selector must be app-root.
    • Its template must be an inline <h1> tag containing the text Welcome to Angular!.

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:

typescript
import { bootstrapApplication } from '@angular/platform-browser';
import { AppComponent } from './app.component';

bootstrapApplication(AppComponent)
  .catch((err) => console.error(err));

app.component.ts should contain:

typescript
import { Component } from '@angular/core';

@Component({
  selector: 'app-root',
  standalone: true,
  imports: [],
  template: '<h1>Welcome to Angular!</h1>',
  styles: []
})
export class AppComponent {}
typescript

Solve the challenge, then check it.

Ctrl+Enter

Course complete!

You've passed every challenge in this course.