Angular is a TypeScript-based framework for building dynamic web applications. It is developed and maintained by Google and is widely used for creating modern Single Page Applications (SPAs).
With Angular, you can:
- Build reusable components.
- Implement powerful data binding.
- Use dependency injection for modular code.
- Develop with the support of a large ecosystem of tools and libraries.
Angular is optimized for building SPAs. A SPA dynamically updates the content of the page without requiring a full-page reload. This improves the user experience by making the application faster and more interactive.
While SPAs are fast and dynamic, they might struggle with:
- SEO (Search Engine Optimization): SPAs are often not SEO-friendly because search engines might not index JavaScript-rendered pages.
- Initial Load Time: The first page might load slower due to JavaScript rendering.
Angular supports SSR with Angular Universal, enabling applications to render HTML on the server before serving it to the browser. This improves:
- SEO performance.
- Faster initial page loading.
In this tutorial, we’ll focus on SPAs initially and introduce SSR later.
Ensure you have the following installed:
- Node.js and npm (Node Package Manager): Angular uses npm to manage dependencies. Download Node.js.
- Angular CLI: A command-line interface tool for creating and managing Angular projects.
Run the following command to install Angular CLI globally:
npm install -g @angular/cli@17
with @17 we are mentioning installtion version
If you don't want to install Angular CLI globally, you can install it locally and use a batch file to run Angular commands without adding it to the PATH.
-
Install Angular CLI locally:
npm install @angular/cli@17
-
Create a batch file:
- Save the following script as
_ng.bat
in your project root:@echo off node_modules\.bin\ng %*
- Use this batch file to run Angular commands. For example:
_ng.bat new my-app
- you have to put this in your workspace, as you can see in repository
- Save the following script as
To create an Angular application, run the following command:
ng g application <app-name>
- Without SSR: At this stage, we won’t enable server-side rendering. (You can later add SSR with Angular Universal.)
- CSS: By default, we’ll use CSS for styling. However, Angular supports other preprocessors:
- SCSS (SASS): For more advanced and modular styling.
- LESS: Another CSS preprocessor.
- Stylus: A minimalist preprocessor.
- To use these alternatives, specify during project creation:
ng g application <app-name> --style=scss
After setting up the application, run the following command to start the development server:
ng serve
- The application will be available at http://localhost:4200.
- Angular is a powerful framework for SPAs and supports SSR.
- Use Angular CLI to set up projects quickly.
- Understand configuration files:
package.json
: Manages dependencies and scripts.angular.json
: Configures build and serve options.tsconfig.json
: Configures TypeScript behavior.
- Start building and exploring Angular components, directives, and modules!