Menu
×
   ❮     
HTML CSS JAVASCRIPT SQL PYTHON JAVA PHP HOW TO W3.CSS C C++ C# BOOTSTRAP REACT MYSQL JQUERY EXCEL XML DJANGO NUMPY PANDAS NODEJS DSA TYPESCRIPT ANGULAR ANGULARJS GIT POSTGRESQL MONGODB ASP AI R GO KOTLIN SASS VUE GEN AI SCIPY CYBERSECURITY DATA SCIENCE INTRO TO PROGRAMMING BASH RUST

Angular First App


Now that your environment is ready, let's create a simple Angular app


Step 1: Open src/main.ts

Angular 20 apps bootstrap a standalone root component.

You can define it inline in main.ts.

Open it an replace the code with:

Example

import { bootstrapApplication } from '@angular/platform-browser';
import { Component } from '@angular/core';

@Component({
  selector: 'app-root',
  standalone: true,
  template: `<h1>Hello, World!</h1>`
})
class App {}

bootstrapApplication(App);

Run Example »

Live reload: When the Angular App is running (Started with ng serve as shown in last chapter), the browser reloads automatically on save.

Quick primer: components

  • A component is a class that controls a view (its template).
  • Each component has a selector (e.g., app-root) that you place in HTML.
  • The root component renders inside index.html's <app-root>.

We'll explore components in depth later: Components.


Step 2: Host element in index.html

Angular renders the root component where its selector appears.

Open src/index.html and make sure the root tag is inside <body>.

The tag must match your component selector from Step 1 (here it is app-root).

If you created the project with the CLI, this tag is usually already present:

Example: Minimal index.html

<!doctype html>
<html lang="en">
  <head>
    <meta charset="utf-8">
    <title>My Angular App</title>
    <base href="/">
    <meta name="viewport" content="width=device-width, initial-scale=1">
  </head>
  <body>
    <!-- Host element -->
    <app-root></app-root>
  </body>
</html>

Keep <base href="/"> in <head> so routing works later.


REMOVE ADS


Step 3: Bind some data

Add a property and show it with interpolation:

Example

import { bootstrapApplication } from '@angular/platform-browser';
import { Component } from '@angular/core';

@Component({
  selector: 'app-root',
  standalone: true,
  template: `<h1>Hello, {{ name }}!</h1>`
})
class App { name = 'Angular 20'; }

bootstrapApplication(App);

Run Example »

Interpolation updates the view automatically when the component property changes.

Tip: Keep expressions simple.

Use properties over calling methods directly in templates for performance.


Project Structure

Key files in a minimal Angular workspace:

  • src/main.ts - Boots the app with bootstrapApplication.
  • src/app/app.component.ts - Root component (if used). You can also define the root inline in main.ts.
  • src/app/ - Where you add your components and features.
  • src/index.html - Host page that contains <app-root>.
  • src/styles.css - Global styles for the app.
  • angular.json - Angular workspace configuration (build, serve, test).
  • package.json - Scripts and dependencies.


×

Contact Sales

If you want to use W3Schools services as an educational institution, team or enterprise, send us an e-mail:
sales@w3schools.com

Report Error

If you want to report an error, or if you want to make a suggestion, send us an e-mail:
help@w3schools.com

W3Schools is optimized for learning and training. Examples might be simplified to improve reading and learning. Tutorials, references, and examples are constantly reviewed to avoid errors, but we cannot warrant full correctness of all content. While using W3Schools, you agree to have read and accepted our terms of use, cookie and privacy policy.

Copyright 1999-2025 by Refsnes Data. All Rights Reserved. W3Schools is Powered by W3.CSS.