Here is a step-by-step guide on getting started with Angular:
- Install Node.js: The first step is to install Node.js which includes the Node Package Manager (NPM). You can download and install it from the official Node.js website.
- Install Angular CLI: Once Node.js is installed, open a command prompt or terminal and run the following command to install Angular CLI globally:
npm install -g @angular/cli
- Create a new project: Run the following command in the command prompt to create a new Angular project:
ng new my-app
This will create a new project with the name
- Serve the application: Navigate to the project directory by running the following command:
Then, serve the application by running the following command:
ng serve --open
This will compile the application and start a development server at
http://localhost:4200/ and open the app in the default browser.
- Edit the application: Open the project directory in a code editor of your choice and start editing the
app.component.htmlfile to modify the HTML template,
app.component.tsfile to modify the TypeScript code, and
styles.cssfile to modify the CSS styling.
- Generate components: To generate a new component, run the following command:
ng generate component my-component
This will create a new component with the name
- Use modules: Angular modules are used to organize the application into cohesive blocks of functionality. To generate a new module, run the following command:
ng generate module my-module
This will create a new module with the name
- Use services: Services are used to share data or logic across components. To generate a new service, run the following command:
ng generate service my-service
This will create a new service with the name
- Build the application: To build the application for production, run the following command:
ng build --prod
This will compile the application into a set of static files in the
dist/ directory that can be deployed to a web server.
- Deploy the application: You can deploy the application to a web server by copying the contents of the
dist/directory to the server’s document root directory.
That’s it! This step-by-step guide should give you a good foundation for getting started with Angular.