Skip to main content

Create a new workspace

Use the Angular CLI to create a new Angular workspace and application:
The ng new command creates a new Angular workspace with a default application. It prompts you with configuration options.

Configuration prompts

When you run ng new, the CLI asks several questions:

Add Angular routing?

  • Yes: Generates a routing module for navigation between views
  • No: Creates a simple single-view application
For your first app, select Yes to explore routing capabilities.

Stylesheet format

Choose your preferred stylesheet format:
  • CSS: Standard cascading stylesheets
  • SCSS: Sass with CSS-like syntax (recommended)
  • Sass: Sass with indented syntax
  • Less: Less preprocessor
For your first app, select CSS to keep things simple.

Installation process

After answering the prompts, the CLI:
  1. Creates a new directory with your app name
  2. Generates the application structure
  3. Installs npm dependencies
  4. Initializes a Git repository
Change to the newly created workspace directory:

Run the development server

Start the Angular development server:
The development server compiles your application and starts a local web server:
Open your browser and navigate to http://localhost:4200. You’ll see the Angular welcome page.
The ng serve command watches your files and automatically rebuilds and reloads the page when you make changes.

Server options

Customize the development server with these common options:

Make your first changes

Now let’s modify the application to understand how Angular components work.

Update the component

Open src/app/app.component.ts in your editor:
src/app/app.component.ts
Key parts of the component:
  • @Component decorator defines the component metadata
  • selector specifies the HTML tag name (<app-root>)
  • templateUrl points to the HTML template file
  • styleUrls references component-specific stylesheets
  • title is a component property available in the template

Modify the property

Change the title property value:
src/app/app.component.ts

Update the template

Open src/app/app.component.html and replace its contents with:
src/app/app.component.html
The {{ title }} syntax is called interpolation and displays the component property value in the template.

See the changes

Save the files and return to your browser. The page automatically updates to show your changes:

Understanding the app module

Angular applications are organized using NgModules. Open src/app/app.module.ts:
src/app/app.module.ts
NgModule properties:
  • declarations: Components, directives, and pipes belonging to this module
  • imports: Other modules this module depends on
  • providers: Services available to the entire application
  • bootstrap: Root component Angular creates and inserts into the HTML host page

Build for production

When you’re ready to deploy your application, create a production build:
The CLI compiles your application into an output directory:
Production builds are optimized:
  • Minified code
  • Tree-shaking to remove unused code
  • Ahead-of-time (AOT) compilation
  • Output hashing for cache busting
The compiled application is saved in the dist/ directory.

Next steps

You’ve created your first Angular application! Continue learning about Angular’s architecture.

Project structure

Understand the files and folders in your Angular workspace

Components

Learn how to build reusable UI components