No history yet

Introduction to Angular

What Is Angular?

Think of building a modern web application like constructing a complex building. You could craft every single brick, wire, and pipe from scratch. Or, you could use a pre-fabricated kit with high-quality, standardized parts that fit together perfectly. Angular is like that kit. It’s a powerful framework, created by Google, for building dynamic and sophisticated web applications.

Angular is used for building single-page applications and is known for its component-based architecture, powerful templating syntax, and robust set of tools for developers.

It uses TypeScript, a superset of JavaScript, which adds features like static typing to help catch errors early. This structure helps developers build large, maintainable applications that can be easily managed by a team. Instead of a loose collection of files, an Angular app is an organized system of interconnected parts.

Core Architecture

Angular organizes code into distinct pieces, each with a specific job. The three most fundamental pieces are Components, Modules, and Services. Understanding how they work together is key to understanding Angular itself.

Let's break these down.

Components are the visual building blocks of your application. Each component controls a patch of the screen called a view. Think of a web page as a collection of components: a navigation bar component, a user profile component, and a post feed component. Each has its own HTML template for the structure and a TypeScript class for the logic.

Modules are containers for a group of related components, services, and other code. They act as a way to organize an application into distinct features and functionalities. Every Angular app has at least one root module, usually called AppModule, which bootstraps the application.

Services are classes that handle tasks not directly related to the view. This could be fetching data from a server, logging user actions, or handling business logic. Components shouldn't do this work themselves; they should delegate it to services. This makes your code cleaner, more reusable, and easier to test.

Getting Started

To start building with Angular, you need two things: Node.js and the Angular Command Line Interface (CLI). Node.js provides the environment to run your JavaScript-based tools, and the Angular CLI is a powerful tool for creating projects, generating application code, and handling development tasks like testing and deployment.

First, install Node.js (which includes npm, the Node package manager) from the official website. Once that's done, you can install the Angular CLI globally on your system by running this command in your terminal:

npm install -g @angular/cli

With the CLI installed, creating a new Angular application is as simple as running one command. Navigate to the directory where you want to create your project and run:

ng new my-first-app

The CLI will ask you a few questions about your project setup (like whether to add Angular routing) and then create a new directory called my-first-app with all the necessary files and dependencies. To see your new app in action, navigate into the directory and run the local development server.

cd my-first-app
ng serve

Now open your web browser and go to http://localhost:4200. You'll see the default welcome page for a new Angular application. You've just created and run your first Angular app!

Lesson image

Time to test your knowledge of these core concepts.

Quiz Questions 1/5

What is the primary purpose of the Angular framework?

Quiz Questions 2/5

What tool must be installed on your system before you can install the Angular CLI?

You've now taken the first step into the world of Angular. By understanding its component-based architecture and using the CLI, you have a solid foundation for building much more complex applications.