Prerequisites
Before you begin, ensure you have Node.js installed on your system. Angular requires an active LTS or maintenance LTS version of Node.js.Check your Node.js version by running
node --version in your terminal. Visit nodejs.org to download the latest LTS version if needed.Installation
Install the Angular CLI
The Angular CLI is a command-line tool that helps you initialize, develop, and maintain Angular applications. Install it globally using your preferred package manager:Verify the installation by checking the CLI version:
Create a new workspace
Use the The CLI will ask you:
ng new command to create a new Angular workspace and application. The CLI will prompt you to configure routing and stylesheet format:- Would you like to add Angular routing? - Type
yfor yes (recommended) - Which stylesheet format would you like to use? - Choose CSS, SCSS, Sass, or Less
Navigate to your project
Change to the newly created project directory:Your project structure will look like this:
Run the development server
Start the development server to see your application in action:The application will compile and start the dev server. Once ready, open your browser to:The dev server includes hot module replacement—changes to your code will automatically reload the browser.
Use
ng serve --open (or ng serve -o) to automatically open your browser to the running application.Create your first component
Now that your application is running, let’s create a custom component to understand Angular’s component architecture.Generate a new component
Use the Angular CLI to generate a new component:Or use the shorthand:The CLI creates four files:
hello.component.ts- Component class with logichello.component.html- Template (HTML)hello.component.css- Styleshello.component.spec.ts- Unit tests
Understanding the component
Let’s break down what makes an Angular component:Component decorator
The@Component decorator provides metadata that tells Angular how to process the class:
- selector: Defines the custom HTML element name
- templateUrl: Points to the HTML template file
- styleUrls: Array of stylesheet paths (styles are scoped to the component)
Data binding
Angular provides several ways to bind data between the component class and template:Using standalone components
Angular’s modern standalone components simplify the development experience by removing the need for NgModules:Building for production
When you’re ready to deploy your application, build it for production:- Compiles your TypeScript code
- Bundles your application
- Optimizes for production (minification, tree-shaking)
- Outputs to the
dist/directory
- Ahead-of-Time (AOT) compilation
- Dead code elimination
- Minification and compression
- Source maps for debugging (optional)
Use
ng build --configuration production to ensure all production optimizations are applied.Running tests
Angular projects come with testing setup out of the box:Next steps
Now that you have a working Angular application, explore these topics to deepen your knowledge:Components & templates
Learn about component architecture, lifecycle hooks, and template syntax
Dependency injection
Understand Angular’s DI system for managing services and dependencies
Routing
Build multi-page applications with the Angular Router
Forms
Create reactive and template-driven forms for user input
Common CLI commands
Here are some frequently used Angular CLI commands:| Command | Description |
|---|---|
ng serve | Start development server |
ng build | Build the project |
ng test | Run unit tests |
ng generate component <name> | Create a new component |
ng generate service <name> | Create a new service |
ng generate module <name> | Create a new module |
ng lint | Lint your code |
ng update | Update Angular dependencies |
