Good tools make application development quicker and easier to maintain than if you did everything by hand.
The Angular-CLI is a command line interface tool that can create a project, add files, and perform a variety of on-going development tasks such as testing, bundling, and deployment.
The goal in this CLI QuickStart chapter is to build and run a super-simple Angular application in TypeScript, using Angular-CLI while adhering to the Style Guide recommendations that benefit every Angular project.
By the end of the chapter, you'll have a basic understanding of development with the CLI and a foundation for both these documentation samples and for real world applications.
You'll pursue these ends in the following high-level steps:
- Set up the development environment
- Create a new project and skeleton application
- Serve the application
- Edit the application
Step 1. Set up the Development Environment
You need to set up your development environment before you can do anything.
Install Node.js® and npm if they are not already on your machine.
Verify that you are running at least node
4.x.x and npm
node -v and
npm -v in a terminal/console window.
Older versions produce errors, but newer versions are fine.
Then install the Angular-CLI globally.
Step 2. Create a new project
Open a terminal window.
Generate a new project and skeleton application by running the following commands:
Patience please. It takes time to set up a new project, most of it spent installing npm packages.
Step 3: Serve the application
Go to the project directory and launch the server.
ng serve command launches the server, watches your files,
and rebuilds the app as you make changes to those files.
Open a browser on
http://localhost:4200/; the app greets you with a message:
Step 4: Edit your first Angular component
The CLI created the first Angular component for you.
This is the root component and it is named
You can find it in
Open the component file and change the
title property from app works! to My First Angular App:
The browser reloads automatically and we see the revised title. That's nice, but we can make it look better.
src/app/cli-quickstart.component.css and give the component some style
That's about all you'd expect to do in a "Hello, World" app.
You're ready to take the Tour of Heroes Tutorial and build a small application that demonstrates the great things you can build with Angular.
Or you can stick around a bit longer to learn about the files in your brand new project.
Project file review
An Angular-CLI project is the foundation for both quick experiments and enterprise solutions.
The first file you should check out is
It has some basic information on how to use CLI commands.
Whenever you want to know more about how Angular-CLI works make sure to visit
the Angular-CLI repository and
Some of the generated files might be unfamiliar to you.
Your app lives in the
All Angular components, templates, styles, images and anything else your app needs go here.
Any files outside of this folder are meant to support building your app.
A folder where you can put images and anything else you need to be copied wholesale when you build your application.
This folder contains one file for each of your destination environments, each exporting simple configuration variables to use on your application. The files will be replaced on-the-fly when you build your app. You might use a different API endpoint for development than you do for production. Or maybe different analytics tokens. Maybe even some mock services. Either way, the CLI has you covered.
Every site wants to look good on the bookmark bar. Get started with your very own Angular icon.
The main html page that is served when someone visits your site.
Most of the time you'll never need to edit it.
The CLI will automatically add all
The main entry point for your app.
Compiles the application with the JIT compiler
and bootstraps the application's root module (
Different browsers have different levels of support of the web standards.
Polyfills help normalize those differences.
You should be pretty safe with
Your global styles go here. Most of the time you'll want to have local styles in your components for easier maintenance, but styles that affect all of your app need to be in a central place.
This is the main entry point for your unit tests. It has some custom configuration that might be unfamiliar, but it's not something you'll need to edit.
Configuration for the TypeScript compiler.
The root folder
src/ folder is just one of the items inside the project's root folder.
Other files help you build, test, maintain, document, and deploy the app.
These files go in the root folder next to
Simple configuration for your editor to make sure everyone that uses your project
has the same basic configuration.
Most editors support an
Git configuration to make sure autogenerated files are not commited to source control.
Configuration for Angular-CLI. In this file you can set several defaults and also configure what files are included when your project is build. Check out the official documentation if you want to know more.
Unit test configuration for the Karma test runner,
used when running
End-to-end test configuration for Protractor,
used when running
Basic documentation for your project, pre-filled with CLI command information. Make sure to enhance it with project documentation so that anyone checking out the repo can build your app!
If you're new to Angular, we recommend staying on the
You can skip the "Setup" chapter since you're already using the Angular-CLI setup.