← Back to Tutorials Chapter 1

Getting Started with Angular

What is Angular?

Angular is a TypeScript-based open-source front-end web application framework led by the Angular team at Google. It is designed for building dynamic, single-page applications (SPAs) with a rich, responsive user interface. First released in 2016 as a complete rewrite of AngularJS, Angular provides a comprehensive solution for client-side development including data binding, dependency injection, routing, and form handling out of the box.

Key Features of Angular

Pros and Cons

Pros

Cons

Environment Setup

Before you start, install the following prerequisites:

  1. Node.js — Download from nodejs.org. Angular requires an active LTS version. Verify with node --version.
  2. npm — Comes with Node.js. Verify with npm --version.
  3. Angular CLI — Install globally: npm install -g @angular/cli. Verify with ng version.
Angular CLI is the primary tool for creating and managing Angular projects. It handles scaffolding, building, testing, and deployment.

Creating Your First App

Open a terminal and run the following commands:

ng new my-first-app
cd my-first-app
ng serve

The ng serve command starts a development server at http://localhost:4200. Open that URL in your browser to see your app running. Any changes you make to source files will automatically reload the browser.

Project Structure

Here is the typical structure of an Angular project:

my-first-app/
  src/
    app/
      app.component.ts    # Root component class
      app.component.html  # Root component template
      app.component.css   # Root component styles
      app.module.ts       # Root module
    assets/               # Static files (images, fonts)
    index.html            # Entry HTML file
    main.ts               # Bootstrap entry point
    styles.css            # Global styles
  angular.json            # CLI configuration
  package.json            # npm dependencies
  tsconfig.json           # TypeScript configuration
Angular project structure

MVC Architecture in Angular

Angular follows a component-based variation of the MVC (Model-View-Controller) pattern. The Model is represented by services and data models, the View by templates (HTML), and the Controller by component classes that manage the logic and state. Unlike traditional MVC, Angular binds these layers together through dependency injection and data binding, creating a cohesive, testable structure.

Angular's architecture promotes loose coupling between components through well-defined interfaces, making your application easier to maintain and extend over time.

Understanding Modules

Every Angular app has at least one module — the root module (AppModule). Modules are decorated with @NgModule and declare which components, directives, pipes, and services belong together. They help organize code into cohesive blocks of functionality.

import { NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { AppComponent } from './app.component';

@NgModule({
  declarations: [AppComponent],
  imports: [BrowserModule],
  providers: [],
  bootstrap: [AppComponent]
})
export class AppModule { }

Main Entry Point

The main.ts file bootstraps the application by passing the root module to the platform:

import { platformBrowserDynamic } from '@angular/platform-browser-dynamic';
import { AppModule } from './app/app.module';

platformBrowserDynamic().bootstrapModule(AppModule)
  .catch(err => console.error(err));

Summary

In this chapter, you learned what Angular is, its core features, how to set up your environment, create a new project, and understand the project structure and MVC architecture. You are now ready to dive into components in Chapter 2.

Exercise 1: Install Node.js and Angular CLI on your machine. Create a new Angular project called hello-angular using ng new. Run ng serve, open http://localhost:4200, and verify you see the default Angular welcome page. Then explore the generated project files and identify each part of the MVC pattern.