Welcome to the tutorial on creating an Angular app! In this guide, we'll walk you through the process of setting up and building a basic Angular application. Whether you're new to Angular or looking to expand your knowledge, this tutorial is for you.

Prerequisites

Before you begin, make sure you have the following prerequisites:

  • Node.js and npm installed
  • Angular CLI installed

Step-by-Step Guide

1. Create a New Angular Project

To create a new Angular project, open your terminal and run the following command:

ng new my-angular-app

This will create a new directory called my-angular-app with all the necessary files and configurations.

2. Navigate to Your Project Directory

Change directory to your new Angular project:

cd my-angular-app

3. Generate a Component

Generate a new component by running:

ng generate component my-component

This will create a new file my-component.component.ts in the src/app directory.

4. Update the App Module

Open src/app/app.module.ts and import the MyComponent:

import { NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { RouterModule } from '@angular/router';

import { AppComponent } from './app.component';
import { MyComponent } from './my-component/my-component.component';

@NgModule({
  declarations: [
    AppComponent,
    MyComponent
  ],
  imports: [
    BrowserModule,
    RouterModule.forRoot([
      { path: '', component: AppComponent },
      { path: 'my-component', component: MyComponent }
    ])
  ],
  providers: [],
  bootstrap: [AppComponent]
})
export class AppModule { }

5. Update the App Component

Open src/app/app.component.html and update the content to include the my-component:

<h1>Welcome to My Angular App!</h1>
<my-component></my-component>

6. Run the Application

Run the application by executing:

ng serve

Open your browser and navigate to http://localhost:4200. You should see the "Welcome to My Angular App!" message and the content of the my-component.

Additional Resources

For more information on Angular, we recommend checking out the Angular official documentation. It's a great resource for learning more about Angular and its features.

Angular Logo


Congratulations! You've successfully created your first Angular app. Keep exploring and expanding your knowledge of Angular to build amazing applications.