Sample Angular Application

Go back to Tutorial

You develop apps in the context of an Angular workspace. A workspace contains the files for one or more projects. A project is the set of files that comprise an app, a library, or end-to-end (e2e) tests. To create a new workspace and initial app project:

  • Run the CLI command ng new and provide the name my-app, as shown here: ng new my-app
  • The ng new command prompts you for information about features to include in the initial app project. Accept the defaults by pressing the Enter or Return key.

The Angular CLI installs the necessary Angular npm packages and other dependencies. This can take a few minutes.

It also creates the following workspace and starter project files:

  • A new workspace, with a root folder named my-app
  • An initial skeleton app project, also called my-app (in the src subfolder)
  • An end-to-end test project (in the e2e subfolder)
  • Related configuration files

The initial app project contains a simple Welcome app, ready to run.

Next Step – Serve the application – Angular includes a server, so that you can easily build and serve your app locally.

  • Go to the workspace folder (my-app).
  • Launch the server by using the CLI command ng serve, with the –open option.

cd my-app

ng serve –open

The ng serve command launches the server, watches your files, and rebuilds the app as you make changes to those files. The –open (or just -o) option automatically opens your browser to http://localhost:4200/.

Edit your first Angular component – Components are the fundamental building blocks of Angular applications. They display data on the screen, listen for user input, and take action based on that input. As part of the initial app, the CLI created the first Angular component for you. It is the root component, and it is named app-root.

Open ./src/app/app.component.ts.

Change the title property from ‘my-app’ to ‘My First Angular App’.



selector: ‘app-root’,

templateUrl: ‘./app.component.html’,

styleUrls: [‘./app.component.css’]


export class AppComponent {

title = ‘My First Angular App!’;


The browser reloads automatically with the revised title. That’s nice, but it could look better. Open ./src/app/app.component.css and give the component some style.


h1 {

color: #369;

font-family: Arial, Helvetica, sans-serif;

font-size: 250%;


Your app greets you with a message:


Go back to Tutorial

Get industry recognized certification – Contact us