Create a new workspace
Use the Angular CLI to create a new Angular workspace and application:ng new command creates a new Angular workspace with a default application. It prompts you with configuration options.
Configuration prompts
When you runng 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
Stylesheet format
- CSS: Standard cascading stylesheets
- SCSS: Sass with CSS-like syntax (recommended)
- Sass: Sass with indented syntax
- Less: Less preprocessor
Installation process
After answering the prompts, the CLI:- Creates a new directory with your app name
- Generates the application structure
- Installs npm dependencies
- Initializes a Git repository
Navigate to workspace
Change to the newly created workspace directory:Run the development server
Start the Angular development server: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
Opensrc/app/app.component.ts in your editor:
src/app/app.component.ts
@Componentdecorator defines the component metadataselectorspecifies the HTML tag name (<app-root>)templateUrlpoints to the HTML template filestyleUrlsreferences component-specific stylesheetstitleis a component property available in the template
Modify the property
Change thetitle property value:
src/app/app.component.ts
Update the template
Opensrc/app/app.component.html and replace its contents with:
src/app/app.component.html
{{ 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. Opensrc/app/app.module.ts:
src/app/app.module.ts
declarations: Components, directives, and pipes belonging to this moduleimports: Other modules this module depends onproviders: Services available to the entire applicationbootstrap: 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:- Minified code
- Tree-shaking to remove unused code
- Ahead-of-time (AOT) compilation
- Output hashing for cache busting
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
