Back to Curriculum

Angular Introduction and Setup

📚 Lesson 1 of 8 ⏱️ 30 min

Angular Introduction and Setup

30 min

Angular is a platform for building mobile and desktop web applications using TypeScript. Developed by Google, Angular is a complete framework (not just a library) that provides everything needed to build large-scale applications. Angular's component-based architecture, dependency injection, and powerful templating system make it ideal for enterprise applications. Understanding Angular's philosophy and architecture is essential for effective Angular development.

It provides a complete framework with tools for development, testing, and deployment. Angular includes a CLI for project scaffolding, a powerful templating system, routing, forms handling, HTTP client, and testing utilities. This 'batteries-included' approach means you don't need to make many decisions about which libraries to use—Angular provides a cohesive, well-integrated solution. Understanding Angular's ecosystem helps you leverage its full power.

Angular CLI is the official command-line interface for Angular development. The CLI automates common tasks like creating components, services, modules, and running the development server. It follows Angular best practices and conventions, ensuring consistent project structure. The CLI also handles build optimization, code generation, and testing. Mastering the CLI significantly speeds up Angular development.

Angular uses TypeScript, which provides static typing, better IDE support, and catches errors at compile time. TypeScript's type system helps prevent bugs and makes code more maintainable. Angular's decorators (@Component, @Injectable, etc.) use TypeScript's metadata to configure components and services. Understanding TypeScript is essential for Angular development, though you can start with basic TypeScript knowledge.

Angular's architecture is based on components, services, and modules. Components are the building blocks of Angular applications, encapsulating template, styles, and logic. Services provide reusable business logic and data access. Modules organize code into cohesive units. Understanding this architecture helps you structure applications effectively. Angular's dependency injection system makes components and services loosely coupled and testable.

Setting up an Angular development environment involves installing Node.js, npm, and Angular CLI. The CLI can generate a complete project structure with best practices built-in. Modern Angular development uses standalone components (Angular 14+) or NgModules for organization. Understanding the setup process and project structure is the first step to productive Angular development.

Key Concepts

  • Angular is a complete framework for building web applications with TypeScript.
  • Angular CLI automates project setup and common development tasks.
  • Angular uses component-based architecture with dependency injection.
  • TypeScript provides type safety and better tooling.
  • Angular includes routing, forms, HTTP, and testing out of the box.

Learning Objectives

Master

  • Setting up Angular development environment
  • Creating Angular projects with Angular CLI
  • Understanding Angular project structure
  • Running and building Angular applications

Develop

  • Understanding Angular's architecture and philosophy
  • Following Angular best practices and conventions
  • Setting up efficient development workflows

Tips

  • Install Angular CLI globally: npm install -g @angular/cli.
  • Use 'ng new' to create projects with routing and styling options.
  • Use 'ng serve' for development server with hot reload.
  • Use 'ng generate component' to create new components quickly.

Common Pitfalls

  • Not installing Node.js and npm before Angular CLI.
  • Using wrong Angular version (check compatibility with Node.js version).
  • Not understanding TypeScript basics, causing compilation errors.
  • Ignoring Angular CLI warnings and errors during setup.

Summary

  • Angular is a complete framework for building web applications.
  • Angular CLI automates development tasks and follows best practices.
  • TypeScript provides type safety and better development experience.
  • Understanding Angular setup is the foundation for Angular development.

Exercise

Create your first Angular application using Angular CLI.

// Install Angular CLI globally
npm install -g @angular/cli

// Create new Angular project
ng new my-angular-app
cd my-angular-app

// Start development server
ng serve

// app.component.ts
import { Component } from '@angular/core';

@Component({
  selector: 'app-root',
  template: `
    <div class="container">
      <h1>{{ title }}</h1>
      <p>{{ message }}</p>
      <button (click)="incrementCount()">
        Clicked {{ count }} times
      </button>
    </div>
  `,
  styles: [`
    .container {
      text-align: center;
      padding: 20px;
    }
    button {
      padding: 10px 20px;
      font-size: 16px;
      cursor: pointer;
    }
  `]
})
export class AppComponent {
  title = 'My First Angular App';
  message = 'Welcome to Angular!';
  count = 0;

  incrementCount() {
    this.count++;
  }
}

Code Editor

Output