0% found this document useful (0 votes)
13 views

Getting Started With Angular 2nd Edition Stephen Adams pdf download

The document provides information about the book 'Getting Started With Angular' by Stephen Adams, which is available for purchase on Leanpub. It includes links to various other recommended Angular-related books and outlines the contents of the book, covering topics such as Angular architecture, components, and the Angular CLI. The book aims to help readers understand and deploy Angular applications effectively.

Uploaded by

rmzneduige
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
13 views

Getting Started With Angular 2nd Edition Stephen Adams pdf download

The document provides information about the book 'Getting Started With Angular' by Stephen Adams, which is available for purchase on Leanpub. It includes links to various other recommended Angular-related books and outlines the contents of the book, covering topics such as Angular architecture, components, and the Angular CLI. The book aims to help readers understand and deploy Angular applications effectively.

Uploaded by

rmzneduige
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 73

Getting Started With Angular 2nd Edition Stephen

Adams download

https://ebookbell.com/product/getting-started-with-angular-2nd-
edition-stephen-adams-22526942

Explore and download more ebooks at ebookbell.com


Here are some recommended products that we believe you will be
interested in. You can click the link to download.

Getting Started With Angular Create And Deploy Angular Applications


1st Edition Victorhugogarcia

https://ebookbell.com/product/getting-started-with-angular-create-and-
deploy-angular-applications-1st-edition-victorhugogarcia-48081270

Getting Started With Angular Second Edition 2nd Edition Minko Gechev

https://ebookbell.com/product/getting-started-with-angular-second-
edition-2nd-edition-minko-gechev-11150184

Getting Started With Typescript Includes Introduction To Angular


Thomas Claudius Huber

https://ebookbell.com/product/getting-started-with-typescript-
includes-introduction-to-angular-thomas-claudius-huber-5726544

The Scalyr Guide To Getting Started Logging As Quickly As Possible


With Quickstart Guides To Logging In Java Log4j2 Php Ruby Rails Swift
Scala Django Angular Meteor Scalyr

https://ebookbell.com/product/the-scalyr-guide-to-getting-started-
logging-as-quickly-as-possible-with-quickstart-guides-to-logging-in-
java-log4j2-php-ruby-rails-swift-scala-django-angular-meteor-
scalyr-50279264
Getting Started With Natural Language Processing Final Release 1st
Edition Ekaterina Kochmar

https://ebookbell.com/product/getting-started-with-natural-language-
processing-final-release-1st-edition-ekaterina-kochmar-46078164

Getting Started With Uno Platform And Winui 3 Handson Building Of


Crossplatform Desktop Mobile And Web Applications That Can Run
Anywhere 1st Edition Andrew Hoefling

https://ebookbell.com/product/getting-started-with-uno-platform-and-
winui-3-handson-building-of-crossplatform-desktop-mobile-and-web-
applications-that-can-run-anywhere-1st-edition-andrew-
hoefling-46364362

Getting Started With Secure Embedded Systems Alexandru Radovici

https://ebookbell.com/product/getting-started-with-secure-embedded-
systems-alexandru-radovici-47255148

Getting Started With Visual Studio 2022 Learning And Implementing New
Features 2nd Dirk Strauss

https://ebookbell.com/product/getting-started-with-visual-
studio-2022-learning-and-implementing-new-features-2nd-dirk-
strauss-47378260

Getting Started With Microsoft Viva An End User Guide To Business


Transformation 1st Edition Darce Hess

https://ebookbell.com/product/getting-started-with-microsoft-viva-an-
end-user-guide-to-business-transformation-1st-edition-darce-
hess-47554262
Getting Started With Angular
Stephen Adams
This book is for sale at http://leanpub.com/getting-started-with-angular

This version was published on 2020-04-01

This is a Leanpub book. Leanpub empowers authors and publishers with the Lean Publishing
process. Lean Publishing is the act of publishing an in-progress ebook using lightweight tools and
many iterations to get reader feedback, pivot until you have the right book and build traction once
you do.

© 2019 - 2020 Stephen Adams


Tweet This Book!
Please help Stephen Adams by spreading the word about this book on Twitter!
The suggested hashtag for this book is #gettingstartedwithangular8.
Find out what other people are saying about the book by clicking on this link to search for this
hashtag on Twitter:
#gettingstartedwithangular8
I thank my wife, Caroline, and children, Georgia and Charlie, who have supported and encouraged
me throughout writing this book.
Contents

Chapter 1: What is Angular? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1


What is Angular? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1
Some examples of the type of projects built with Angular . . . . . . . . . . . . . . . . . . . . 2
Angular’s history . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2
Why use Angular? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3
Features of Angular . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7
The Client Contacts Manager Application . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10
Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11

Chapter 2: Angular Architecture . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12


Overview of Angular . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12
Installing the Angular CLI . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14
Installing Visual Studio Code . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15
The architecture of an Angular app . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18
The architecture of our Client Contacts application . . . . . . . . . . . . . . . . . . . . . . . . 27
Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 30

Chapter 3: Getting Started with the Angular CLI . . . . . . . . . . . . . . . . . . . . . . . . . . . 31


How a CLI helps Angular developers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 31
Installing the Angular CLI . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 32
Creating the Client Contacts Manager application . . . . . . . . . . . . . . . . . . . . . . . . . 32
Running your application in the browser . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 35
Commands of the Angular CLI . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 37
What are Schematics? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 45
Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 46

Chapter 4: Components, Templates, and Forms . . . . . . . . . . . . . . . . . . . . . . . . . . . . 47


Components . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 47
What are components? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 47
Why do we have components now? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 48
The structure of a component . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 50
The Component class . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 51
The component life cycle hooks . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 51
Passing data into and out of components . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 55
CONTENTS

Component templates . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 61
Categories of components . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 66
An introduction to forms . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 68
Creating a Reactive form . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 75
When to use template forms . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 79
When to use Reactive forms . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 80
Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 80

Chapter 5: NgModules . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 81
What are modules in Angular? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 81
The parts of the NgModule file . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 83
How to create modules using the CLI . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 87
Creating modules for our Client Contact Manager application . . . . . . . . . . . . . . . . . 89
Adding our Client components to the ClientModule . . . . . . . . . . . . . . . . . . . . . . . 92
Adding Angular Material . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 96
Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 102

Chapter 6: Routing and Navigation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 103


What are routes? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 103
Creating our navigation component . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 111
Route parameters . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 120
Route Guards . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 123
Implementing a Route Guard . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 124
Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 125

Chapter 7: Dependency Injection, Services, and HttpClient . . . . . . . . . . . . . . . . . . . . 127


What is Dependency Injection? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 127
How does Angular handle Dependency Injection . . . . . . . . . . . . . . . . . . . . . . . . . 129
Providers in Angular . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 134
Services in Angular . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 138
A look at the services Angular provides . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 140
The HttpClient service . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 140
Features of the HttpClient API . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 142
Advanced features of HttpClient service . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 147
Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 151

Chapter 8: Observables and RxJs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 152


Observables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 152
What is RxJs? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 162
Operators . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 166
Examples of Operators . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 167
The Operator Decision Tree . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 176
Subjects . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 176
How Angular uses RxJs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 179
CONTENTS

Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 182

Chapter 9: State Management and NgRx . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 183


Defining state management . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 184
The Redux library . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 186
Exploring NgRx . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 189
Example of a Reducer . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 190
Example of an Action . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 191
Example of the Store . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 191
Example of Selectors . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 195
Effects . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 196
Installing NgRx . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 199
Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 200
Further Reading . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 200

Chapter 10: Testing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 202


Testing and Test Driven Development . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 202
Jasmine in action . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 204
Setup and tear down of tests . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 208
The Karma test runner . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 209
Taking a Test Driven Development approach . . . . . . . . . . . . . . . . . . . . . . . . . . . . 213
Karma settings in Angular . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 214
Running tests using the Angular CLI . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 217
Writing tests in Angular . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 218
The TestBed class . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 221
Examples of tests . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 224
Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 231

Chapter 11: Packaging Our Application . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 232


Building a release version with the CLI . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 232
The angular.json file . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 236
Ahead-of-Time compilation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 239
Other various production optimisations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 241
Making use of lazy loading . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 244
Application size budget . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 245
Measuring performance . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 246

Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 248
Chapter 1: What is Angular?
Welcome to this book on Getting Started with Angular. Throughout this book, we will be exploring
Angular and how to get started building applications with Angular. We will be looking at topics
such as how to set up an Angular application and how to use the tools the Angular team provide
to begin developing an Angular application. We will look at the architecture of a typical Angular
application and how components and modules are used to build sections of the app. We will explore
ways data is accessed and passed in an app and what mechanisms Angular provides for managing
data.
We will also look at more advanced topics, such as observables and RxJS, testing, and packaging an
application for production. We will even take a look at the NgRx, which is a library for managing
state.
In this chapter, we will introduce Angular, what it is, and the reasons it is an ideal choice for web
application development, as well as go through the features of Angular and what’s in the latest
release, version 8.
I will also introduce the demo application we are going to be building throughout the book. So, to
recap, in this chapter, we will cover the following topics: - Why are we looking at Angular? - What is
Angular? - Some examples of the types of applications that can be built with Angular - The history
of Angular, how it was started, and what problems it aimed to solve What are the new features of
Angular - What is the demo application we will be building throughout this book

What is Angular?
According to the official Angular docs, Angular is a platform that makes it easy to build applications
with the web. Awesome, but what does that actually mean? Well, Angular is a web application
framework that helps developers build web applications, web applications that can run on all
platforms, from desktop and mobile, which makes Angular an ideal choice for your next web
application.
The official documentation goes on to describe Angular as, [combining] declarative templates, de-
pendency injection, end-to-end tooling, and integrated best practices to solve development challenges.
Angular empowers developers to build applications that live on the web, mobile, or the desktop.
This perfectly describes what Angular is. Through templates, dependency injection, and end-to-end
tooling, Angular empowers developers to build web applications and applications that are built on
best practices.
Chapter 1: What is Angular? 2

Some examples of the type of projects built with


Angular
By learning Angular, you can build many different types of applications, using the one framework.
For example, you can build a complete web application, such as the Google Grab and Go program,
where enterprise companies can manage their usage of Chromebooks.
Google announced the Grab and Go program for Chromebooks, powered by Angular at the
following URL: https://blog.angular.io/google- announces-grab-and-go-program-for-chromebooks-
powered-by-angular-7954c11900bd.¹
If you ever wanted to build an email client, you can in Angular. There is already a project called
ProtonMail, which is a full-featured email client developed by scientists and engineers from CERN,
written in Angular.
You can also build desktop applications in Angular. Working along with Electron (Electron | Build
cross-platform desktop apps with JavaScript, HTML, and CSS), the Node-based framework for
building cross-platform desktop apps, you can use Angular as the framework to structure your code
while letting Electron manage the running of the application on the desktop. A great example of this
type of project is Nrwl’s Angular Console application, which provides Angular developers with a
UI in order to work with the Angular CLI (more on the CLI later).
And, of course, there is mobile; through using projects such as Angular Material, you can create
Angular applications that are designed to look exactly like native mobile applications, (especially if
you are building for Android). Now, while Angular will allow you to create a web application that
looks and acts like it will run as a native application, Angular doesn’t solve the problem of how to
install the project as a native mobile application, along with the full native support of the phone’s
features. That’s where a project like Ionic comes in. But, as you can see, a developer who knows
how to write Angular applications has a lot of variety for the projects they can build.

Angular’s history
The history of Angular is an interesting one; first, there was AngularJS, and then came Angular.
AngularJS was created as part of an internal project within Google by Misko Hevery. He created
the first version of the project to make it easier for the designers within his team to build web
applications.
Misko wanted a way to extend the vocabulary of HTML in order for the designers to use HTML
tags that were more relevant to what they were designing. So, over a long weekend, yes, that’s a
weekend, Misko came up with the first version of AngularJS. The name Angular came from the
angled brackets that are at the beginning and the end of an HTML tag.
¹https:/ / blog. angular. io/ google-announces- grab- and- go- program- for- chromebooks- powered- by-angular- 7954c11900bd
Chapter 1: What is Angular? 3

Brad Green, Misko’s team leader at the time, asked Misko to work on a project called the Google
Feedback Tool, which was written in Google Web Kit (GWT), a Java-based framework. But, after
six months working on the project with GWT, the team found that it was extremely difficult to
work with. So, Misko said that he could rewrite the Feedback Tool project in two weeks using his
side project, AngularJS. Unfortunately, he took three weeks to complete the project, but he reduced
the number of lines of code down to 1,500 from the 17,000, which is the amount the old GWT version
had. And all this in three weeks as a solo developer!
Brad was obviously impressed, so he asked other developers to help Misko to work further on
Angular; Igor Minor (who still works on Angular along with Misko) and Shyam Seshadri both helped
Misko to complete the rewrite of the Google Feedback Tool and develop AngularJS further.
The next project the team worked on with AngularJS was the DoubleClick application that Google
had just purchased. The team was challenged to create a new landing page for DoubleClick; first,
they tried using GWT, but, after a two-week struggle, they turned to AngularJS, which Misko had
been promoting within Google. They were able to complete the landing page project within two
days using AngularJS. As a result of this success, the DoubleClick team decided to use AngularJS.
With this, the first version of AngularJS was released in May 2011.
But this is all about AngularJS; we’re not looking at the previous version. We’re interested in the
latest version of Angular, its second iteration. This new version of Angular came out in September
2016, after two and a half years of development, which shows how much thought has gone into the
new version.

Why use Angular?


Why should a developer decide to learn Angular? Well, there are several reasons, but the main
reason is so they can create applications for all platforms: desktop, mobile, and the web. All these
platforms are reachable for a developer who knows how to write Angular applications.
There are other similar technologies out there; for example, there are many JavaScript frameworks
like Angular, but Angular is extremely well established and supported by Google. It is an ideal
frontend framework for enterprise-level application, with all the out-of-the-box features that come
with Angular (including modules, classes, components, and unit testing), All of these are extremely
important to enterprises wanting their teams to develop well structured, tested applications;
applications that are going to work the first time for their clients.
There is also a huge ecosystem around Angular; teams such as Nrwl with their Nx Extensions,
which allow teams to create libraries to support the large enterprise-level applications that Nrwl
specialises in. There is also a vast amount of training resources available to an Angular developer;
companies such as Plurasight, EggHead, and Ultimate Angular all have in-depth courses for Angular
development.
There are a large number of reasons why we should use Angular as our web application framework
of choice. Let’s look at these reasons.
Chapter 1: What is Angular? 4

Supported by Google
One of the main reasons to use Angular is because it is supported by Google. They don’t just sponsor
the development of Angular, they are the team behind the development of Angular; Unlike other
frameworks, which are supported by open source developers who work on fixing issues and creating
new features for a framework in their spare time, Angular has a full-time team constantly working
on supporting Angular.
Google has also provided a Long Term Support (LTS) plan for Angular, which shows that they plan
to support older versions of Angular for the next few years. In this LTS, we can see what versions of
Angular they provide support for and when older versions will no longer be supported. With Google
being so transparent in terms of their support of Angular, we can be sure that it has a long future.
This is extremely important for large businesses looking to select the framework they are going to
invest in for their next large-scale project. Being able to see that Angular has the support of a large
organisation like Google, and that there is an LTS plan, which shows that Angular will be supported
for the long term, makes the decision to pick Angular as their framework of choice a straightforward
one.
See the release dates from the official Angular website: https://angular.io/guide/releases.²

Built on TypeScript
Angular is built on TypeScript, a superset of JavaScript, from Microsoft. TypeScript brings so many
benefits, including Type interfaces and static typing. When we create objects and variables within
our code through static typing, the details of these types are known when we compile our code
and this helps to provide insight. So, bugs can be found at compile time instead of runtime. Not
only does TypeScript help us write better code, but it also allows tools such as VSCode to provide
IntelliSense of our code, which gives us better navigation, refactoring, and autocompletion, making
the experience of writing TypeScript far more enjoyable than JavaScript.
Along with providing a great development experience, as a result of using TypeScript, we have access
to all the ES2016/ES2017 features that aren’t yet available in JavaScript. TypeScript can provide
features that are still to be released in JavaScript. Being able to compile down to ES2015 (the version
of JavaScript that the browser understands), TypeScript can provide these latest features and still be
able to generate ES2015 code.
So, being built on TypeScript, Angular has access to all the latest features of the language and all
the fantastic tooling TypeScript provides.

The Angular CLI


Another great reason for using Angular is the Angular CLI; this is a command-line tool provided
by the Angular team that helps us to build and run Angular projects. The CLI comes with a wide
²https:/ / angular.io/ guide/ releases
Chapter 1: What is Angular? 5

range of features, including the following: - Creating the start of a project - Creates components,
services, directives, and other files using a simple command - Runs the application in the browser -
Reloads the application after each saved change so that the latest version is displayed in the browser
- It can update a project’s dependencies (other libraries used in a project) automatically - It can add
new libraries to the project - It can run all the unit tests in a project and the end-to-end tests
The Angular CLI is a great tool, and you’ll see as we proceed that learning Angular is an important
part of developing Angular applications. Many other frontend frameworks don’t have CLIs, and
those that do, they do not have the features of the Angular CLI.

Command-Line Interface (CLI) is a way of writing commands to the computer via a


Terminal window.

Built on best practices


Angular is designed with best practices in mind. Any code generated by the CLI follows these best
practices, as set out by the team from Google. By following the approach prescribed by the Angular
team on how to write an Angular application, you know that the application you are building is
using the best practices of modern web applications.
These best practices include the following: - Component-based architecture - Modularised structure
- Dependency injection - Testing - Readable code - Ease of maintenance
Being built on a set of best practices means that you know the architecture of your application is
built on the basis of these good practices.

Testing is a first-class citizen of Angular


Testing is an extremely important part of creating bug-free applications. Angular supports testing
straight out of the box. Whenever the CLI creates a new Component or Service, it automatically
creates a Test Spec file for the new Component or Service. The CLI can also run the tests. No longer
do we have to set up test runner files; all of this is automatically managed by the CLI.
Making writing tests and running tests are so easy, so there is no reason not to have a good set of
tests for your application. Angular actively encourages writing tests, and by doing this, it reduces
bugs and issues that an end user may find, thereby making Angular an ideal choice for large-scale
enterprise level applications.

The Angular community


Another great reason for choosing Angular as your framework of choice is the community that
has grown around Angular. There are over 100,000 Angular developers, a number that is still
growing. There are Angular meetups all around the world, where you can go and meet other Angular
developers to discuss their experiences with using Angular and you can learn from them.
Chapter 1: What is Angular? 6

There are also many conferences you can attend as an Angular developer to learn about the
new features of Angular and hear talks on different approaches to working with Angular. These
conferences are all over the world, and attended by the Angular team, so you can put your questions
to the team directly.
Not only are there conferences and meetups you can attend to learn about Angular, but there
are also so many online resources created by members of the Angular community that we
can access to learn about Angular. There are sites such as Ultimate Courses (https:// ultimate-
courses.com/courses/angular³) who provide courses on Angular and TypeScript.
There are also podcasts where you hear interviews with leaders of the Angular community, including
the Angular team. Podcasts such as Adventures in Angular and EggHead.io provide great interviews
with Angular developers.

Access to third-party libraries


The Angular community, as well as allowing us to learn from one another, is also active in building
libraries and tools that work with Angular. Libraries such as NgRx, NGXS, and MobX all provide
solutions on how to manage state within an Angular application (NgRx is something we will
explore in Chapter 9, State Management and NgRx). There are also UI libraries such as Angular
Material, NGX-Bootstrap, and Nebular, which provide UI components you can add to your Angular
applications.
There are libraries for accessing data from cloud-based systems, such as Firebase. So, if your
application needs to connect to an existing Firebase application, there are libraries you can add
that simplify working with Firebase in your application. You can also find libraries that facilitate
working with GraphQL if that’s how your team creates their APIs.
If you want to add tools to your Angular workflow, the Angular community has provided tools
like Augury (https://augury.rangle.io⁴) from Rangle.io, which is a plugin for Chrome for debugging
Angular applications.
Another great tool from the Angular community is the NX workspaces from Nrwl. They have
created an extension to the Angular CLI that helps to create large enterprise Angular applications,
where teams of developers work on the same project. The NX tool helps the CLI create libraries
within Angular projects so that large-scale teams can share code across teams.

To see the types of extra resources available for Angular, look at the Resources list on the
Angular website: https://angular.io/resources.⁵

As you can see, there are so many reasons to use Angular. We’re already on version 8, which shows
that the Angular team aren’t slowing down in terms of making Angular better and better. Let’s now
go through some of the recent features of Angular and see what’s new in Angular.
³https:/ /ultimatecourses. com/ courses/ angular
⁴https:/ / augury. rangle. io
⁵https:/ / angular. io/ resources.
Chapter 1: What is Angular? 7

Features of Angular
As we know, Angular provides a framework for developing web applications, but there is more
to Angular than just the building blocks of a web application (components, services, directives,
and so on). Angular has many features we can use as Angular developers to create fast, powerful
applications.

Schematics
The first feature we’re going to look at is schematics. This is a tool we can add to our workflow as
Angular developers, similar to how we use the Angular CLI. Schematics allow us to apply transforms
to our projects; we see an example of this when we ask the Angular CLI to create Components or
Services for our application.
When we call the CLI to create a Component file, it updates the filesystem where our project is kept.
So, the CLI is writing to the filesystem. You’ll see as we progress through this book that the Angular
CLI is really helpful at starting up and adding to a project.
While the CLI is a wonderful workflow tool, the role of schematics is to build upon this scaffolding
feature that the CLI supports. So, schematics allow us to add to the project in a way that we can
get the CLI to build new features as part of our project. For example, we could write a schematic
that will add a new library to a project. Or, we could have a schematic that adds a UI library, which
is standard across all projects within an organisation, to a new Angular project. If your company
has a set of UI components that need to be used in any project, we could write a schematic, which
is called through the CLI, that will add this UI library and create the new Angular project in one
process.
Schematics don’t write to our filesystem; they update a Tree object. This Tree object is a represen-
tation of our project’s filesystem, and when a schematic is run, this Tree object is updated with the
new updates, as set out in the schematic’s rules.
A schematic is a TypeScript file that has the rules for this new schematic set out within this file. In
the schematic file, the Tree data object can be updated and added to. So, we can update the Tree to
have new files, or add new libraries.
Tools such as Nrwl’s NX workspaces make use of schematics to add to the workflow of the Angular
CLI. So, if your project is using the NX workspaces, you can run commands that create libraries that
will be shared across teams.

To read more about NX and how it makes use of schematics, check out the NX workspaces
website: https://nx.dev/getting-started/nx-and-cli⁶.
⁶https:/ / nx. dev/ getting- started/ nx- and- cli
Chapter 1: What is Angular? 8

CLI prompts
Another feature is CLI prompts, where the Angular CLI will ask questions when we run a command
such as ng add or ng generate (both commands we will see in use throughout the book). The CLI
will prompt the user with questions such as Which stylesheet format would you like to use? or Would
you like to add Angular routing?.
We can also create these prompts for our own schematics, so when a team member is running one
of our schematics through the Angular CLI, they will be prompted with questions we want them
to be asked as the schematic is running in order for them to make different choices in terms of the
features our schematic may be adding to the project it is building.
The great benefit of having CLI prompts is that it helps developers discover new features of the CLI.
With each release of the CLI, the team can add new prompts, asking if we want to make use of any
new features that are part of a new Angular release.

Angular Elements
A really interesting new feature of Angular is Angular Elements. Angular Elements is the ability to
create custom web components that can be loaded into any modern browser.
Through these web components, we can create small Angular applications, which will run as part
of the web page. For example, if you have a web page built using ASP.Net, but a small section of the
page needs to use a piece of functionality that is already in an Angular application, with Angular
Elements, you can convert that Angular application to a web component that will run within the
ASP.Net page as a standalone piece of functionality.
Web components are a feature of the Web Platform (https://www.w3.org/Talks/2012/10- lea-
webplatform/wpd-talk/#intro⁷) and are supported by all modern web browsers. They allow us, as
web developers, to extend HTML by creating our own tags, which the browser will understand.
We can package up HTML, CSS, and JavaScript to create one of these Web Components, which the
browser can understand and run, just like it would a standard HTML tag.
With Angular Elements, a Web Component made with HTML, CSS, and JavaScript can also have the
Angular framework incorporated into the component, giving us access to all that Angular provides.
This means our component can, in essence, be a mini-Angular application, running within any
other type of web page. So, if we have a React page that needs to have a feature from an Angular
application, it can be loaded via Angular Elements.
One area where I’ve found Angular elements to be extremely useful is when there is an AngularJS
application that needs upgrading to Angular (AngularJS will no longer be supported after 2021).
With Angular Elements, we can create new features for an existing AngularJS site and then load
this new feature into the AngularJS site using Angular Elements. Then, as the AngularJS code is
rewritten in Angular, each new part can be loaded into the original application via an Angular
Element. Once everything has been written in Angular, the AngularJS code can be removed and we
⁷https:/ / www. w3. org/ Talks/ 2012/ 10-lea- webplatform/ wpd- talk/ #intro
Chapter 1: What is Angular? 9

now have everything written in Angular. The end user will not notice a difference. Well, perhaps
the application will load faster for them, but that’s not a problem!

The Ivy Renderer


Another feature of Angular is the new view renderer engine called Ivy.
Ivy provides so many great features, including the following: - Easier-to-read generated code. - Faster
rebuild times between updates. - Small payload sizes, especially production-ready code. The smaller
the payload, the faster the application loads. - Improved Type checking in our HTML templates.
While Ivy is nearly ready, it’s not quite set for production-ready applications, so if you want to play
with it to see the great benefits it brings, then use the preceding command to create an application
that uses Ivy. Then, you’ll be able to see how much smaller the final size of the application Ivy
generates is and how fast it reloads between each build.
A great place to find out about Ivy is the Angular Next website, which is a guide with documentation
on some of the new features coming in Angular. You can find this guide by going to Angular Next
(https://next.angular.io/guide/ivy⁸).

CLI Builders
Another new feature in Angular is CLI Builders. This is a new API that allows us to add to, and
build upon, features with the Angular CLI.
We currently have schematics, which, as we know, allow us to write commands that the CLI can
use to generate new code for our applications. CLI Builders expands on this and provides an API we
can use to write commands to the CLI’s build system.
While schematics give us the ability to ask the CLI to generate new files or install new packages
for us, for example, adding Angular Material as part of a new application can be handled through
a schematic. With CLI Builders, the Angular team have expanded on this openness to the CLI and
have provided us with a way to write commands that can change the build system of Angular.
Through CLI Builders, we can run commands and tasks against the CLI to build our Angular
applications in any way we want. So, for example, as part of the build, we may need to have all
Angular Libraries built at the same time, or have all our tests run as part of the build; these tasks
can now be set up through the CLI Builder API.

Differential loading of JavaScript


In Angular, the CLI will now produce both ES5 and ES2015 JavaScript. ES5 is a legacy version of
JavaScript, while ES2015 is the latest version of JavaScript with all the modern features we now
expect of JavaScript. This will improve loading times in today’s modern browsers, as they will be
given the ES2015 version of the bundled code instead of the legacy ES5 version, which is far slower.
⁸https:/ / next. angular. io/ guide/ ivy
Chapter 1: What is Angular? 10

The Angular route improvements


Another new feature of Angular is the fact that the routing in our applications has been improved
to support AngularJS routing. By doing this, it will help with upgrading an AngularJS application
to Angular because the routing of an application is usually the last thing to be upgraded.
In Angular, there will be a backward compatibility mode for the router, so it will understand how to
run the AngularJS version of the router, and lazy-loading is supported for the AngularJS router. This
is a real benefit for those on AngularJS looking to upgrade before AngularJS is no longer supported.

Library updates
Along with all these new features in Angular, all the versions of RxJS, TypeScript, and Node have
been updated to their latest versions. So, we can start taking advantage of the new features from
these libraries as well.
Angular has some really nice new features; it is expanding in terms of opening up the Angular CLI
to us as developers so that we can tailor the CLI to our needs; it’s also adding features to help with
the upgrade from AngularJS to Angular.
The way we write Angular applications, which we will learn in this book, still applies to Angular 8,
so once you know how to create applications with Angular, you can then explore further these new
features in Angular.

The Client Contacts Manager Application


So, throughout this book, we are going to be building a sales team contacts app for a fictional
company. The idea behind this app is to have a system that allows the fictional sales team of our
fictional company to manage and access the contact details of their clients and the companies they
work with. This mini-CRM (Customer Relationship Manager) allows us to create an app that uses a
number of features so we can really explore the features of Angular. This application’s main features
are that it allows us to add, edit, and view the details of customers. We can also filter the list of
customers using the built-in features of Angular.
We can look at how we will create the UI using Angular components and Angular Material. We can
look at how we will build up the model of the application, how data will be passed throughout our
app as we build up the functionality to add new customers, save their details, and see a list of all of
our saved customer contacts.
We will see how Angular uses TypeScript, which gives us excellent tooling and insight into our code,
making the development process even easier than before when we were using JavaScript.
The idea is to create two versions of the mini-CRM that the salesperson will use; the mobile version
will be used when they are out and about talking to their customers, and the desktop app will be
used when back in the office to search for all the new wonderful customers they have.
Chapter 1: What is Angular? 11

As part of this application, we are going to use a fantastic third-party library called the In- Memory
Web API (https://github.com/angular/in-memory-web-api⁹). This library allows us to create local,
in-memory storage similar to a database that we can save data to, access data from, and remove data
from, all via API calls.
Using this library means we have a source of storage for our Client Contacts Manager Application
and we can make API calls to this storage system without having to set up a local database of external
API. We can just focus on learning how to write Angular.
Once you’ve finished reading this book, and you’ll want to create your own application to practice
what you’ve learned, I highly recommend looking at the In Memory Web API as a temporary data
source for your practice applications; it’s not a replacement for a real database, but is really easy to
use for small demo applications.

Summary
So, we have looked at what Angular is, what problems it aims to solve, and a bit about the history
of Angular. We have looked at some examples of the types of projects we can build using Angular
and have gone through the new features of Angular.
Finally, we’ve looked at what we will be building throughout this book, how we will be creating
a mini-CRM, which gives us the ability to really explore the features of Angular. So by the end of
this book, you should not only have an understanding of both frameworks, but you’ll also be able
to create apps in Angular.
Next, we are going to start working the Angular version of the application. We’re going to start
building the app using the Angular CLI, and we will look at the architecture of an Angular
application.
⁹https:/ / github. com/ angular/ in- memory- web- api
Chapter 2: Angular Architecture
Now that you know what Angular and Ionic are, it’s time to start looking into things more deeply.
In the first part of this book, we’re going to be concentrating on Angular, and in this chapter, we’re
going to be looking at the architecture of an Angular application.
How are we going to do that? Well, we need an application to look at, in order to see the various
parts of the application: what they are, what they do, and how they are built. In order to do this, we
need to create an Angular application, and in order to do that, we need to install the Angular CLI.
So, let’s do that.
In this chapter, we’ll be looking at the architecture of an Angular application to see how the Angular
framework structures a typical application. You’ll also learn how the various parts of an Angular
application are pieced together. Here’s what you’ll be learning in this chapter:

• Why Angular is an ideal frontend framework


• How an Angular application is structured
• What modules are, what components are, and how they are used
• What dependency injection is and how services are loaded
• Why TypeScript is used, and the benefits it brings
• The structure of the app being built throughout the first part of this book

Overview of Angular
Angular is more than just a framework; it’s now both a framework and a platform. In the previous
version, AngularJS was just a frontend framework, but now, with more advanced frontend tools,
Angular has grown from a frontend framework into a complete platform.
Being a complete platform, Angular can now be used to create a wider variety of applications;
before, AngularJS was used for creating Single-Page Applications (SPAs). As more and more teams
used AngularJS as the basis for their tools, AngularJS could be used to develop different types of
applications.
With Angular (the second version of AngularJS), as there are more mature tools for frontend
development, the Angular team has been able to expand Angular from a frontend framework into
this complete platform. It’s a platform that allows developers to create web apps, mobile apps,
desktop apps, and even server-side applications.
Chapter 2: Angular Architecture 13

The problem Angular solves


The main problem that Angular aims to solve, like all other application frameworks, is providing
the developer with a consistent way to develop and deploy applications. Angular has a set approach
to building a web application that is based on some best practices. The team behind Angular
have created the framework, so when we (as Angular developers) build our applications using the
framework, we are using the current best practices for developing web applications. We do not have
to worry about whether we are writing our applications using the best approach, as the framework
has these best practices already built in.
Following the approach of a framework means that as a developer, you don’t have to worry about
some of the more mundane parts of building an app (for example, making HTTP calls to an API).
This is something that is becoming a standard feature in web apps. Having to create a service that
makes your HTTP calls over and over again every time you start a new project is a waste of time if
you have a framework that can take this away from you; in that case, all you need to do is make a
call to the framework’s HTTP service. This saves you plenty of time to worry about other parts of
your application.
Angular, unlike other popular web frameworks, provides you with a lot of out-of-the-box features
that they think you will need when building modern web applications. This includes things like
HTTP access services, a module system, a build system, a way to package your app for production,
and a routing system, so that your users can navigate around the application you’ve built.
The second main problem that Angular aims to solve is providing developers with a set approach to
how to build modern web applications. By having this prescribed approach, Angular developers can
simply focus on the domain-specific problems of the application and not have to worry about how
they will handle the more common features of an application (like navigation, for example). When I
say domain-specific problems, I mean the problems that the web application is trying to solve. The
time that is spent trying to work out a method of navigation for your application can now be spent
working on the problems that the app is trying to solve.
Another problem that Angular solves is a collaboration between developers. Having a framework
like Angular is like following a map for how an Angular application is set out. As you’ll see when
we look into the architecture of the Angular and Ionic apps that we are going to build throughout
this book, there are many similarities between the applications’ structures. Someone that is only an
Angular developer would be able to go through the code of an Ionic application and know how the
application works, and vice versa; a developer who is mainly an Ionic developer can go through the
source code of an Angular application and have an idea of how the app works.
This common knowledge of how an Angular application works helps developers to collaborate on a
different project far faster than an application that’s not built using a framework. This is great not
only for onboarding new developers to a team, but for open source development, as well.
So, to recap, Angular gives you a set approach based on the best practices for modern web
development. It gives you many out-of-the-box features that you will need to build an application.
Its common patterns make learning how a new Angular application works quicker, and onboarding
Chapter 2: Angular Architecture 14

new developers to your project/team is easier and smoother.


Now, we are going to create a small demo application, which we will use to look at the basic structure
of an Angular application; however, we first need to install the Angular CLI, which is the main tool
you’ll use to create Angular applications.

Installing the Angular CLI


To install the Angular CLI, we need Node, so we need to go to the Node website and install it.
So, let’s go to the Node website at https://nodejs.org/en/¹⁰. Once we’re there, we need to click
on the download link for the Long Term Stable (LTS) version of Node. This version of Node is
recommended for most users and is ideal for our needs.
Once the download has completed, click through the installation wizard and complete the installa-
tion of Node. Then, when that has finished, we need to open up our Terminal or Command Prompt
and check the version of Node we’ve just installed. To do this, run node -v you should see the version
number come up, which confirms that Node has been installed.
OK, that’s done; now, to install the Angular CLI.

Why do I need to install the CLI when I’ve just installed Node? The answer is, we need
Node Package Manager (NPM), to install the Angular CLI for us.

Again, in your Terminal or Command Prompt, run the following command:


npm install -g @angular/cli

This command is telling npm to go and install the Angular CLI package globally (so that it’s available
from anywhere, within any folder). Then, npm goes off and downloads the latest version of the
Angular CLI and installs it for you. The days of CDs or floppy disks are long gone; it’s all command-
line magic now.
Now, we should have the Angular CLI installed, and it’s time to create our first Angular app. This
isn’t going to be the Client Contact demo app that I mentioned earlier; this is just going to be a small
app with which we can look through the code and see how an Angular app is made and what the
structure of the app is.
To create an Angular application, we need to go back into our Terminal or Command Prompt and
navigate to a folder in which we can work. Once we have navigated to our development folder, we
simply run the command ng new, along with the name of the Angular app we’re building. So, for
this, type in the following:
ng new angular-architecture
¹⁰https:/ /nodejs.org/en/
Chapter 2: Angular Architecture 15

This will create a new folder within the development folder, called angular-architecture. The CLI
uses the name you provide to create a new folder in which to create the application. Once that has
run, you should see the following message:
Project 'angular-architecture' successfully created

Congratulations! You’ve created your first Angular app.


So, let’s recap on what we’ve done. We’ve installed Node, because we need npm to install the Angular
CLI. We installed the CLI, and then we created a new Angular application. We are going to leave
the Angular CLI for now; there will be more on what the CLI is and how you will use the CLI as an
Angular developer later, in Chapter 3, Getting Started with the Angular CLI. Now, we need to start
looking at the code the CLI has generated; to do that, we need to open the angular-architecture
folder in our favourite editor.

Installing Visual Studio Code


Ask a room full of developers what their favourite editor is, and you’ll get a thousand different
answers. One thing is for sure: there is no correct answer. For this book, we’re going to be using
Visual Studio Code, for the following two reasons:

• It’s free, so you can download it with no cost to yourself


• It works well with Angular

There are other great editors available for writing Angular applications, like Webstorm, Atom, and
even Visual Studio itself. All of these are good editors for Angular, but we are using Visual Studio
Code because it’s free and good with Angular. With the power of the Angular CLI, you could (in
theory) use Notepad with the Terminal to create an Angular application, but why would you do that
to yourself?
If you don’t already have Visual Studio Code (more commonly called VSCode), go to https://code.visualstudio.com/¹¹
and download the latest version. Once that’s installed, let’s open up VSCode and navigate to our
newly created Angular app.
You should see the following screenshot:
¹¹https:/ / code. visualstudio. com/
Chapter 2: Angular Architecture 16

VSCode showing our Angular application

This is VSCode with our new app loaded. We can now use the features of VSCode to go through the
app and see how it’s structured.
First, let’s expand the source tree folder; you should see the full src folder, as follows:
Chapter 2: Angular Architecture 17

VSCode showing the src folder

There are a few main parts to the app; the first thing you’ll notice is that there are two main folders,
the src folder and the e2e folder. The src folder contains all the source code for your app. It will
contain all the HTML, CSS, and TypeScript code of your app. The e2e folder contains all your end-
to-end tests, and these tests can be run to test how your app runs in the browser. However, we are
looking at the architecture of an Angular app, so let’s carry on with that.
Within the src folder, you’ll see the app folder, and inside of that you’ll see the following files:

• app.component.css
• app.component.html
• app.component.spec.ts
• app.component.ts
• app.module.ts

We now have a small Angular app, which we can take a look at while we go through the architecture
of an Angular application.
Chapter 2: Angular Architecture 18

The architecture of an Angular app


Okay, now we have discussed the problems Angular solves, and we’ve even created our first Angular
application; it’s time to discuss how an Angular app is structured.
Angular is essentially a framework and a platform, written using HTML and TypeScript. The
functionality of the application is written in TypeScript files that can be imported throughout the
app as libraries, adding functionality throughout the app.
When the Angular application app is run in the browser, these TypeScript files are converted into
JavaScript files, which are then bundled up into the payload that is delivered to the browser (there
are ways that this payload can be separated into smaller, separate files in order to keep its size down,
but this is something we will briefly look at in Chapter 3, Getting Started with the Angular CLI ).
There are three main parts to an Angular application, and they are as follows:

• Modules: Modules are the glue that holds an application together. They are single TypeScript
files that reference all the other files used within the application. They allow us as Angular
developers to group the functionality of our application together.
• Components: Components are the building blocks of the application. They are single pieces of
functionality in our application, which are linked together under a module. Components can
have visual elements to them, which allow the user to interact with the application.
• Services: Services are single TypeScript classes used to access information and share it between
components.

When you think of an Angular application, you can think of it as a tree; the module is the trunk
of the tree, and the components are the branches of the tree, branching out of the module, with
services being passed into components to share data throughout the application. Everything is tied
together through the module, and as the complexity of your Angular application grows, the number
of modules you’ll have in your application will grow.
Now let’s take a more in-depth look at each of these three parts, starting with modules.

What are modules?


We’ve now provided an overview of the general structure of an Angular app, so we’re going to be
looking further into modules, or, as they are known in the Angular world, NgModules. To see an
example of a module, open the app.module.ts file of our Angular app.
You should see the following:
Chapter 2: Angular Architecture 19

1 import { NgModule } from '@angular/core';


2 import { AppComponent } from './app.component';
3 @NgModule({
4 declarations: [
5 AppComponent
6 ],
7 imports: [
8 BrowserModule
9 ],
10 providers: [],
11 bootstrap: [AppComponent]
12 })
13 export class AppModule { }

This is the main App module; as you can see, it’s made up of four main parts: the declarations array,
the imports array, the providers array, and the bootstrap array. There is another part to a module
that is not shown in this example: the Exports array.
So, what do all these different arrays do? Well, let’s look at each one, as follows:

• declarations: This contains the components, directives, and pipes that are part of this module.
• imports: This contains other modules, whose classes are needed by components of the module
they are being imported into.
• providers: This contains any services that are required by components. If a service is added to
the module level, it is available to all components that are part of the module, but services can
also be imported at just the component level.
• bootstrap: This contains the main component, or the root component, which starts the whole
application. Only the root module (in our architecture application it’s the app.module.ts file)
that we have opened can have a Bootstrap array.
• export: This contains a list of declarations that are available by components in other modules.

One of the first things to point out is the use of a decorator to tell Angular about the details of
this module. As you can see, the @NgModule is a decorator. Angular sees this and knows that this
TypeScript class is a module, and, that the details within the @NgModule decorator are all parts of
this module. So, through this decorator, Angular knows that this module has its own version of
AppComponent that belongs to this module. It then imports another module called BrowserModule,
and when Angular boots up, it should use the AppComponent as part of this Bootstrap process.
NgModule’s main role is to tell the framework what components belong where when the application
is being compiled. For example, suppose that I have a component called ComponentOne.ts, and in
the same application, another developer working on the project also creates a new component and
decides to call it ComponentOne.ts, adding it to the same project. The compiler wouldn’t know which
ComponentOne to use when the application was running. By using a module, we can say that one
Chapter 2: Angular Architecture 20

ComponentOne belongs to this module, and the other one belongs to another module. Then, when
the compiler is running the application and it is running the code that belongs to a module, the
compiler knows which ComponentOne file to use. This helps to group functionality together and
allows a different developer to work on separate parts of an application without affecting the part
of the application that another developer is working on.
With NgModule, we can say that one ComponentOne.ts belongs to the admin modules, admin.module.ts,
and the other ComponentOne.ts belongs to the ordering module, ordering.module.ts; so now, each
component has a context of where it belongs. So, Angular knows where each ComponentOne belongs
and that they are separate components. Although naming components the same name is never a
good idea, it’s sometimes unavoidable, especially when incorporating a third-party library into your
project.
We will be going further into NgModule in Chapter 5, NgModules, where we will not only look into
a more complex module file, but will also start to create modules for our demo app.

What are components?


We’ve already mentioned components; they are one of the main building blocks of an Angu-
lar application. Again, going back to our angular-architecture demo application, if we open
app.component.ts, we will see the following:

1 @Component({
2 selector: 'app-root',
3 templateUrl: './app.component.html',
4 styleUrls: ['./app.component.css'
5 })
6 export class AppComponent {
7 title = 'app'
8 }

This is the entry component of our application. If you look at the app.module.ts file, you’ll see
that AppComponent is set to be the Bootstrap component for the application. That means that this
component will be the start of the application, and the template for this component will be the first
thing a user will see when the app has loaded in the browser.
Again, the component is a TypeScript class that is using the @Component decorator to tell Angular
about the details of the component. In this @Component decorator, we can see that the component
has an HTML template called app.component.html and a CSS file called app.component.css.
The @Component decorator also tells Angular that the selector, or HTML tag, for this component is
app-root; this is the HTML that the selector generates:

<app-root></app-root>
Chapter 2: Angular Architecture 21

The selector name is used to create the HTML tag that Angular knows about, so when that HTML tag
is seen in other component templates, Angular knows what component to use and what component’s
template to display.
In our example component within the class, we can see a property of the component class called
title. This property is available in the associated template of the component, which you can see in
the following section of app.component.html:

1 <div style="text-align:center">
2 <h1>Welcome to {{ title }}!</h1>
3 </div>

There’s more that can be added to the component class besides properties that are available to the
associated template/view. The functionality of the template is defined in the component class, as
well as data and common functionality provided by Services is loaded into the component class,
making it available to the component template.
We’ll be looking at components more closely in a later chapter. We’ll be creating new components for
our demo application and looking more closely at the relationship between the component class and
the component template. But for now, this should give you an understanding of the basic structure
of an Angular component.
Now, we are going to look at Services: how they are structured, and how Decorators are used to
define what a Service is in Angular.

What are Services?


You now know what NgModules are and what components are, so we’re going to take a look at
another major part of an Angular application: Services.
A Service is simply a TypeScript class, similar to how a component has a TypeScript class. The
main difference between a component class and a service is that services are used to create more
modularity and reusability within the application. They are used as a way to share functionality that
may be needed more than once throughout the application. This helps to improve the modularity
of the application by dividing functionality into reusable and standalone services that components
call in to do a single piece of the app’s functionality. This leads to the app being divided up into
these smaller services, rather than having all the logic of the app in one large, monolithic service or
component.
Services are there to do one thing and one thing well. This means that the component can load in
Services to do the one piece of logic the component requires; then, the component can call another
service to perform another piece of logic that the component needs. This leads to a component
needing to have access to multiple services. Angular loads services into components through
Dependency Injection.
Chapter 2: Angular Architecture 22

Dependency Injection (DI) is the method that Angular uses to tell components what services the
component can consume. DI is not just an Angular-specific concept; there are many frameworks
that use Dependency Injection, and not just frontend frameworks.
Angular has always used DI. Even from the early versions of AngularJS, DI has been the method
that Angular has used to inject Services into components.
In our angular-architecture project, we don’t have a service automatically generated for us by the
Angular CLI. This is because (as we know), services are used to manage data and logic within our
application. This changes from application to application. The Angular CLI team couldn’t get the
CLI to generate a service for us that fits the needs of our application, it’s impossible. So, they don’t
provide a service for a very basic Angular application (although, as we will see in Chapter 3, Getting
Started with the Angular CLI, the CLI can generate Services); we have to create one ourselves.
While the angular-architecture application doesn’t have a service, we can still take a look at an
example to see the structure of a Service.
In the Angular official documentation, there is an example application called Tour of Heroes, and
it is possible to download and view the source code of this example application. (It’s well worth
doing this, as the Tour of Heroes application has great examples of the various parts of an Angular
application. It was written by some of the leading experts within the Angular community, so it’s a
great example of some best practices for building Angular apps.)
In this Tour of Heroes application, there are many Services that we can take a look at to see how a
Service is structured. This is one of the main services, which loads a list of Heros from an external
API:

1 export class HeroService {


2 private heroes: Hero[] = [];
3 constructor(private backend: BackendService, private logger: Logger) {}
4
5 getHeroes() {
6 this.backend.getAll(Hero).then( (heroes: Hero[]) => {
7 this.logger.log(`Fetched ${heroes.length} heroes.`);
8 this.heroes.push(...heroes); // fill cache
9 });
10 return this.heroes;
11 }
12 }

As you can see, it is a simple TypeScript class with a Constructor and a single method called
getHeros(). It also calls another service, called BackendService (showing an example of this
modularity that services provide, where one service does one single task and uses another to perform
another task, in this case providing data).
Chapter 2: Angular Architecture 23

What’s missing from this Service is the Decorator that tells Angular that this class can be
consumed/injected into Components. The Decorator that provides Angular with this information is
called the Injectable decorator, and it looks like this:

1 @Injectable({
2 providedIn: 'root',
3 })
4 export class HeroService {}

When the @Injectable decorator is added to a class, this tells Angular that this class and its
functionality can be passed into components and other services, using Dependency Injection.
To get a better understanding of how a service is linked to a module, let’s create a simple Service for
our angular-architecture app. Within VSCode, we need to open the Terminal panel (if you open
the Terminal drop-down menu in the main navigation, you should see the New Terminal link).
This is shown in the following screenshot:

VSCode Showing Terminal Menu

This will open a new Terminal window at the bottom of VSCode, with the folder of our project
already loaded. In this new window, type the following:
ng generate service demo
Chapter 2: Angular Architecture 24

This will tell the Angular CLI to create a new service called demo within our source code. We will
be looking at the commands of the CLI in more detail later on, in Chapter 3, Getting Started with
the Angular CLI.
So, you should have a nice new service called demo.service.ts, which looks like the following:

1 import { Injectable } from '@angular/core';


2 @Injectable()
3 export class DemoService {
4 constructor() { }
5
6 }
7 }

Pretty impressive? Well, not really, because it doesn’t actually do anything yet, but it does
demonstrate how the TypeScript class is using the @Injectable decorator so that Angular knows
that this class can be injected into components and other services via DI.
Now that we have this service, let’s add it to our app.module.ts file so that Angular knows what
context this service belongs under.
Open the app.module.ts file, which should look like this:

1 import { BrowserModule } from '@angular/platform-browser';


2 import { NgModule } from '@angular/core';
3 import { AppComponent } from './app.component';
4 @NgModule({
5 declarations: [
6 AppComponent
7 ],
8 imports: [
9 BrowserModule
10 ],
11 providers: [],
12 bootstrap: [AppComponent]
13 })
14 export class AppModule { }

To add the service, we type the name of the service to the providers array, like this:
Chapter 2: Angular Architecture 25

1 providers: [
2 DemoService
3 ],

VSCode should automatically set the import statement at the top to where the service TypeScript
class is stored, as shown here:

1 import { AppComponent } from './app.component';


2 import { DemoService } from './demo.service';

The final stage is to have the app.component.ts consume the new DemoService. To do that, we add
the service to the constructor of the component class, as follows:

1 import { Component } from '@angular/core';


2 import { DemoService } from './demo.service';
3
4 @Component({
5 selector: 'app-root',
6 templateUrl: './app.component.html',
7 styleUrls: ['./app.component.css']
8 })
9 export class AppComponent {
10 title = 'app';
11 constructor(public demoService: DemoService) {}
12 }

Here, we have given the DemoService a local name of demoService, so if we want to access any of
the functions of the service within our component class, we simply use the following local reference:
this.demoService.methodCall();

So, we’ve now created a service using the CLI, added it to our module so Angular knows about it,
and added it to our main component class; that’s quite a lot. Now, we are going to take a look at
why Angular is built with TypeScript and what benefits this brings to us as Angular developers.

Why use TypeScript?


In AngularJS, everything was written in JavaScript; with the new version of Angular, the decision
was made to write everything using Typescript. Why was there this change from JavaScript to
TypeScript? Well, there are many reasons, but first, let’s take a look at what TypeScript is.
TypeScript (https://www.typescriptlang.org/¹²) is from Microsoft, and according to the official
website, it’s a superset of JavaScript that compiles down to plain JavaScript. What this means is
¹²https:/ /www.typescriptlang.org/
Chapter 2: Angular Architecture 26

that TypeScript has a larger set of features that JavaScript doesn’t have, but when you save your
TypeScript file, the TypeScript compiler transforms the TypeScript code you have written to just
plain JavaScript. But why do we need TypeScript?
Well, the simple reason is that JavaScript, while a fantastic language, moves slowly when adding
new features. For a new feature to be added to the language, it has to be discussed by all the
relevant committees (JavaScript, while not being owned by anyone, is governed by a committee of
community leaders and representatives for the various web browser developers). These committees
need to discuss a new feature: how it’ll be implemented, how it’ll be used by developers, and the
benefits it brings. Then, they make it part of the ECMAScript standard, which is a document that
sets out what languages based on ECMAScript should be able to do.
Then, all the various browsers need to start adding support for these new features of JavaScript into
their browser, and the JavaScript engine, which is part of the browser. Therefore, when one browser
supports a new feature, this allows a developer to use that feature and for it to work in the browser.
Another browser company may not have implemented it, so when a user views a website or web
application using this new feature, it won’t work for them.
The introduction of new features is a slow process in JavaScript. It has become faster over the last
few years as the popularity of JavaScript has grown, but there are still a lot of hurdles for a new
language feature to be added to plain JavaScript.
Microsoft decided that they would create a new language—not to replace JavaScript (like they tried
with JScript a few years ago), but so that this new language would have the features that they
believed a modern web language should have. With their knowledge and experience in developing
tools, they would create a compiler for this new language that would generate JavaScript that used
its set of features to replicate the new features of this new language. This would allow the developer
to use the latest features of a modern web language and leave the compiler to work out how to
mimic these features in JavaScript.
This is what TypeScript aims to do; Microsoft can add all the new features they want to TypeScript—
features they believe a language should have (based on their experience with other languages, such
as C#). These features include types, interfaces, and modules (although these are now available in
JavaScript), and there is no wait for these features to be available to developers. Developers know
that support for these new language features is made by the TypeScript compiler.

Why is Angular written in TypeScript?


Angular is written in TypeScript because it provides so much insight and powerful tooling. One of
the core developers of Angular, Victor Savkin, said the following:
“The biggest selling point of TypeScript is tooling. It provides advanced autocompletion, navigation,
and refactoring. Having such tools is almost a requirement for large projects. Without them, the fear
changing the code puts the code base in a semi-read-only state and makes large-scale refactorings
very risky and costly.”
– Victor Savkin, Angular: Why TypeScript?
Chapter 2: Angular Architecture 27

You can find the article here: https://vsavkin.com/writing-angular-2- in-typescript-1fa77c78d8e8¹³

Not only does TypeScript provide great features that aren’t available in JavaScript, it also provides
great tooling for developers to use in order to find issues and bugs within their code before it’s even
run in the browser.
For example, we are using VSCode throughout this book to build both our Angular and Ionic
applications, and both applications use TypeScript. As we go through building out these applications,
TypeScript, and more specifically the TypeScript compiler, is inspecting our code and is aware of all
the different parts of our code. If we add a property to a class then use that class in another class
(as we did when we added our demo service to our main component class), the TypeScript compiler
knows what functions are available from this demo service. Therefore, when we go to use the service
in the component class, VSCode knows what is available and gives us developer insight into what
functions are available as we type.
For me, the main benefit that TypeScript provides is this insight into our code as we write. An
application can become more and more complex, and trying to remember all the moving parts
is extremely hard, but with TypeScript and the great tooling it gives us, there is less we need to
remember and a lower chance of bugs appearing in the code.
As well as great tooling, TypeScript allows us to make abstractions when we are defining the model
of our application. Using interfaces, which TypeScript provides us, allows us to define how our
application will be structured and the relationships between the parts of the data model that our
application uses. This is something we will be looking at in the next section, where we’ll go over the
architecture of our Client Contacts application.
Moving from JavaScript to TypeScript can be difficult, to start with. When you start writing
TypeScript, the compiler keeps telling you the mistakes and problems with your code as you type,
while JavaScript would just let you get away with these simple mistakes. Therefore, you would think
that JavaScript is quicker to develop with, but the more and more you work with TypeScript, the
better your code becomes and the better you become. Soon, you’ll be writing code that is easier to
read and understand.

The architecture of our Client Contacts application


We’ve already spoken about it a couple of times, but throughout this book, we’ll be building a Clients
Contacts Manager application for both the desktop browsers, using Angular. Since we’ve been
looking at the Angular architecture, we are now going to take a high-level look at the architecture
of the Angular version.
The main features of this application are as follows:

• View a list of contacts


¹³https:/ /vsavkin.com/writing- angular-2-in-typescript-1fa77c78d8e8
Chapter 2: Angular Architecture 28

• Search through the available contacts


• View the details of a selected contact
• Edit the details of a contact
• Add a new contact to the system Remove a contact

There’s also going to be a Company section, because each contact must belong to a company, as our
fictional salesperson needs to be able to find the contacts for a particular company.
So, in the Company section, the salesperson will be able to do the following:

• View all the companies


• Search for a company by name
• View the details of a selected company
• Edit the details of a selected company
• Add a new company to the system
• Remove a company from the system

If we think about the model behind this application, there are three main data models: the contact,
the company, and the salesperson who uses the application. Each of them can have an Interface that
defines the details of the model and what each model representation can do.
So, the interface for the salesperson could be as follows:

1 interface SalesPerson {
2 firstname: string;
3 lastname: string;
4 email: string;
5 password: string;
6 jobtitle: string;
7 startDate: Date;
8 active: boolean;
9 accessLevel: number;
10 relatedCompanies: Companies[];
11 relatedContacts: Contacts[];
12 }

Here, we have set some properties that a salesperson will have: firstname, email, startDate, and so
on. We’ve also created properties that they may have for relatedCompanies and relatedContacts.
Both of these are defined as arrays with a type of Companies and Contacts, which are Types we
define for the data model of the other sections of the application.
The Contact interface looks as follows:
Chapter 2: Angular Architecture 29

1 interface Contact {
2 id: number;
3 firstname: string;
4 lastname: string;
5 email: string;
6 jobtitle: string;
7 status: string;
8 isActive: boolean;
9 relatedCompany: Company;
10 notes: string;
11 }

Here, we are defining the model of a contact to have an ID; a first name and last name; some
details about their job, such as the status; and the Company they belong to, which is set as the
relatedCompany property that is a type of Company.
Finally, our Company Interface will look as follows:

1 interface Company {
2 id: number;
3 name: string;
4 address1: string;
5 address2: string;
6 town: string;
7 city: string;
8 postCode: string;
9 country: string;
10 contactEmail: string;
11 numberOfStaff: string;
12 industry: string;
13 isActive: boolean;
14 }

As you can see, we’ve created a Company type that has a name, address details, some information
about the number of staff, and the industry the company works in. This Company type is the type
that is used for the relatedCompany property of the Contact type. Now that we have a few interfaces
mapped out, it shows how the features of TypeScript allow us to abstract the model of the application
into types that our application will use.
What else do we need for our application? Well, here’s an initial list of the components and services
we need for this application:

• Main app component


Chapter 2: Angular Architecture 30

• Main nav component


• Header component
• Login form component
• Contact form component
• Company form component
• Add a new contact button component Search form component
• List of contacts component
• Service to manage the salesperson’s access
• Service to manage the contacts
• Service to manage the company
• Service to manage saving data to an external data source All the CSS for styling the app

That’s a lot of components and services, and there may be more! We won’t create these now; instead,
we’ll start to create these components and services using the Angular CLI, which is what we will be
looking at in Chapter 3, Getting Started with the Angular CLI.

Summary
In this chapter, we set up a new Angular application using the CLI, and we reviewed the main parts of
the application. We discussed how modules, components, and services are the building blocks of an
Angular application. Then, we looked at why the Angular team made the decision to use TypeScript
as their language of choice for Angular. We took a look at the architecture for the demo Angular
application that we are going to start building in Chapter 3, Getting Started with the Angular CLI,
when we will be taking a more detailed look at the Angular CLI.
Chapter 3: Getting Started with the
Angular CLI
In the previous chapter, we took a quick look at the Angular CLI; we used it to create our
architecture-application project. Now, we’re going to be taking a closer look at the CLI.
We’ll be using the CLI to create our demo project and to run the application in the browser. Then,
we will see how to use the CLI to create new components and templates. We’ll also look at other
commands you can pass to the CLI, and see what other tasks it can perform. Once we’ve gone
through all this, we’ll take a look at schematics, the latest feature of the CLI. We’ll cover what
schematics are, and how they are being used.
In this chapter, we will cover the following:

• What is the Angular CLI?


• Installing the Angular CLI
• Creating an application using the CLI
• Running the application in the browser
• Updating packages in your application using the CLI An overview of other CLI commands
• Using the CLI to package an application for production What are Schematics?

How a CLI helps Angular developers


A CLI is a tool that is designed to provide features that will help a developer in their day-to-day
work. The Angular CLI, which is written in Node, is a tool that runs in your Terminal or Command
Prompt that will be running in the background as you develop your application.
It’s there so you can use it as you work; the type of things it can do for you include the following:

• Generating a new Angular application


• Creating new components, services, and files for your Angular application
• Running the application in the browser
• Reloading the browser every time there is a change, so you always see the latest version
• Running your Unit Tests Running the end-to-end tests

These are just a few of the features of the Angular CLI. As you can see from this list, having a tool
that you can use to run these tasks as you are developing is beneficial.
Now that you can build an Angular application without a CLI, you can create all the files yourself,
set up a build tool that’ll minimise all your files, and run the application in the browser. You can set
up Karma to run all your unit tests. But all these tasks would take a lot of time within a project to
set up and manage.
Chapter 3: Getting Started with the Angular CLI 32

Installing the Angular CLI


In the previous chapter, we went through the steps for installing the latest version of the Angular
CLI, but it’s worth going through these steps again (in case you missed them in the previous chapter).
Anyway, here’s how to install the Angular CLI. First, we need to install Node, as we will be using
NPM to install Angular. So, go to the NodeJs website, https://nodejs.org¹⁴.
Select the latest Long Term Support (LTS) version of Node, which, in this screenshot of the NodeJS
website, is version 10.13.0.
Once Node has downloaded, run the installation wizard. Once that has finished, open Terminal or
Command Prompt, and let’s look at the version number to check that everything has been installed
successfully.
To check the version number, run this command:
node -v

You should see the version number appear in Terminal/Command Prompt, which should be the
same as the version you have just downloaded.
OK; now that Node is installed, it’s time to get the Angular CLI. To do this, in the Terminal/Command
Prompt window, type the following:
npm install -g @angular/cli

In this command, we are telling Node to use the Node Package Manager (NPM) to install globally,
so that it is available in any folder you choose.
Once this has run, we can check that the Angular CLI has been installed by typing this command:
ng -v

This will tell us what version of the Angular CLI we have installed, which, at the time of writing, is
version 8.0.2.
That’s it; the Angular CLI has been installed. Now, we’re going to look at how we can use it, and
we’ll start to create our Client Contacts Angular app.

Creating the Client Contacts Manager application


We now have the Angular CLI installed, and we know it’s working, because we’ve seen the version
number. So we’re going to start to create the Client Contacts Manager application.
So, let’s get started!
First, let’s go to our main working folder. I like to keep my projects under a Dev folder, so again, in
Terminal, let’s navigate to this working folder. So, type the following command:
¹⁴https:/ / nodejs. org
Chapter 3: Getting Started with the Angular CLI 33

cd Dev

That has taken us to our Dev folder; what we should do next is create a folder for our Angular apps.
So, in Terminal, type the following:
mkdir Getting-Started-With-Angular-8

This will create a new folder called Getting-Started-Angular-8. This is where we will build both of
our Angular applications. Now, you need to cd into this new directory using the following command:
cd Getting-Started-With-Angular-8

Once we’re there, we need to tell the Angular CLI to create a new Angular application. To tell the
Angular CLI to create an application, we simply use the following command:
ng new Client-Contacts-Manager

This will create a new folder within the Getting-Started-Angular-8 folder called Client-Contacts-Manager,
where the CLI will create all the shell code of the application. As the CLI runs, it will ask you the
following two questions:

1. Would you like to add Angular routing?


2. Which stylesheet format would you like to use?

Project Setup Commands

Basically, the CLI is asking: Do we want to add routing to the application? Routing is how you set up
navigation throughout an application, and by saying yes, we are asking the CLI to create a Routing
module, where all our links can be added to a separate module. We will be going over Routing in
Chapter 6, Routing and Navigation; but for now, say Yes.
The second question is asking: What CSS format do we want to use in this application? We can use
just plain CSS for the application, but we are going to choose SASS.
Chapter 3: Getting Started with the Angular CLI 34

After agreeing to these two questions, the CLI will create a folder called Client-Contacts-Manager
and add all the scaffolding code for the application. Once the CLI has finished, cd into the folder
that has just been created:
cd Client-Contacts-Manager

Then, type the following:


code .

This will open Visual Studio Code, with our newly created Angular application loaded. You should
see the following screenshot:

VSCode showing our new project

This screenshot shows Visual Studio Code with the Client-Contacts-Manager folder loaded in the
left-hand side project view.

Exploring VSCode
Let’s take a minute here to explore VSCode. From the preceding screenshot, we can see that there
are two main panels in the VSCode editor. On the left side, we have the Project Explorer, which
shows us all the files of our project, or the project opened in VSCode. On the right-hand side is the
editor, where we can see any files that have been opened.
Chapter 3: Getting Started with the Angular CLI 35

If we double-click on a file listed in the left-hand side Project Explorer, the selected file opens in the
right-hand Editor view. We can also use the shortcut command of Ctrl/Cmd + P to open the quick
access tool, which allows us to start typing in the name of a file we want to open. Once we’ve found
the file we want to access, all we do is press Enter, and that file will open in the Editor view. This is
another way to open files, and it’s a lot faster than searching through the Project View panel.
The panel below the Editor view shows the built-in Terminal, which is an application that all
computers have, whether it’s macOS or PC, which allows us as developers to type commands to tell
the computer to do something. We’ve used Terminal a few times now when installing the Angular
CLI and creating our development folder, but now we can see we have access to this Terminal tool
within VSCode, which makes it easy to access while we are building our application.
Now we’ve had a brief overview of VSCode, we can carry on building our Angular application.
Awesome, we are on our way to Angular mastery!

Running your application in the browser


Now that we have our application generated by the CLI, it’s a perfect time to run the application
and see what the CLI has created for us. Not only will the CLI build an application for us, but it will
run the application in the browser for us. To do this, we need to open Terminal within VSCode and
then run this command:
ng serve
Or alternatively you can run this command:
npm run
You should see that the application has compiled successfully as shown in the following screenshot:

Terminal Running Our App


Chapter 3: Getting Started with the Angular CLI 36

The Angular CLI has compiled all the source code of the application and started running a new
Node server making the application accessible at this web address: http://localhost:4200.
If you open this URL in your favourite browser, you should see the newly generated Angular app as
follows:

Our app running in the browser

What we have here is our application running in the browser. As part of building a new application,
the CLI generates an initial page with some helpful links. These links are as follows:

• Tour of Heroes: A demo application created by the Angular team, which you can read about
in the Angular documentation and see a live demo
• CLI Documentation: A link to the wiki page of the Angular CLI team with details on how to
use the CLI and a list of other commands
• Angular blog: The Medium blog of the Angular team, well worth reading and checking
regularly to see what the team are up to
Chapter 3: Getting Started with the Angular CLI 37

Now as we’ve seen, running the app and then opening the browser is easy, but there is an even
easier way to get the application running in the browser. We can tell the CLI to not only start the
application but open the browser and load the application for us.
So now, close the browser and in VSCode terminal use CMD/CTRL + C to stop the Node service
running. Then, within the same Terminal window, type the following command:
ng serve -o

This tells the CLI to compile the application, start the Node service running again, and even open
the browser loading the application again at http://localhost:4200.
You should now see the same web application running in your browser as we did before, but this
time, there was no need to go and open the browser and enter the URL of the site, the Angular CLI
has done all this for you.
This is a small example of how the Angular can help improve the development processes. There are
many commands that the CLI provides, which you can use to tell the CLI to help you as you build
out your Angular application. Let’s pause for a minute to look at some of these commands and how
they can help.

Commands of the Angular CLI


So we know the Angular CLI can be used to start a new application and also run the new application
in the browser, but that’s not all it can do. There are other commands we can use as Angular
developers as we are developing our applications.

A command is a term for instructions we type into the Command Line Interface (CLI).

Let’s now go to the official Angular website to find the official documentation for the CLI as shown
in the following screenshot:
Chapter 3: Getting Started with the Angular CLI 38

The Angular CLI Documentation

Once the site has loaded, we will see a list on the left-hand side of all the available commands. There
are the following:

• ng add: Used to add third-party libraries to an existing application, we will be using this soon
to add Angular Material.
• ng build: Used to compile the complete application into a /dist folder or a folder provided by
an argument.
• ng config: Allows you to either view or set configuration settings for your app, these
configuration settings can be passed as JSON.
• ng doc: Opens the official Angular docs website, if you want to find a specific topic, add the
keyword as an argument
• ng e2e: This will run the end-to-end tests of the application.
• ng generate: Command to create/generate new components, services, and other parts of your
Angular application. This command we will be using a lot over the next few chapters.
Chapter 3: Getting Started with the Angular CLI 39

• ng help: This provides you with a help menu for the Angular CLI.
• ng lint: Runs linting over your application’s codebase.
• ng new: This starts the process to create a new Angular application, we’ve already used this
command.
• ng run: This starts running a custom target for your application. In your package.json file, you
can add custom commands that ng run will start for you.
• ng serve: Starts the local Node server so you can access the site in the browser. ng test: Starts
the running of all the Unit Tests you create for your application.
• ng update: This will update the application and any dependencies in the application, very
useful when a new version of Angular is released.
• ng version: Tells you the version number of the Angular CLI currently being used.
• ng xi18n: Extracts any xi18n messages within your application, used as part of adding multi-
language support to your application.

Wow, that is a lot of commands, 15 in total, and there may be more coming in future releases of the
Angular CLI. This shows how much you can do with the CLI and how you will rely on it as part of
your day-to-day Angular development. We are now going to take two of these commands and use
them with our newly created Client Contacts Manager application.

Using ng add to add Angular Material


Angular Material (https://material.angular.io/¹⁵) is a UI library that provides a set of UI components
you can use in your Angular application. They give the application a Material look; when I say
Material, I don’t mean like carpet, but using the Material look that Google has been using in many
of its web applications and in the Android mobile platform. You’ve already seen this Material look
in the official Angular website.
So why are we going to be adding this to our application? Well, the Angular Material UI does give
a nice polished look to web applications, and we don’t want to be spending the time creating loads
of CSS to create a half decent looking application. Also, this does give us an opportunity to use the
Angular CLI and add Angular Material via the CLI.
To do this, we need to open up the terminal and navigate to the newly created Client-Contacts-Manager
folder. Once there, you need to run this command:
ng add @angular/material

This will start a process where the CLI will install all the dependencies and libraries needed for
Angular Material, it will also install the main CSS file into our main index.html file.
After running this command, the CLI will be asking you a series of questions as follows:

• What pre-built theme do you want to use?


¹⁵https:/ / material. angular. io/
Chapter 3: Getting Started with the Angular CLI 40

• Do you want to use HammerJS for handling gestures? This gives you support for gestures on
mobile.
• Do you want to use animations? This will give your app the smooth effects that you’d expect
with that Material design style

Adding Angular Material

This shows the Angular CLI after it has asked its setup questions and updated the modules
automatically. As you can see, main.ts has been updated, so has app.modules.ts. This is where
the CLI has added the links and modules of Angular Material to our project automatically.
So now that this is complete, let us run our application to see how it looks in the browser. Again we
can use the CLI to run the app, using the following command:
ng serve -o

This will open the browser with the updated application, looking like the following screenshot:
Chapter 3: Getting Started with the Angular CLI 41

Client Contacts Manager using Material

Now, the site doesn’t look completely different, but that’s because we haven’t started adding Material
specific components, but you can see that the fonts are different and the padding around the side of
the application has been reduced. This is all because of the newly installed CSS file of the Angular
Material library the CLI has installed.

Using ng test to run Unit Tests


Unit Tests are an extremely important part of modern web application development. So much so,
Angular creates tests for every component or service automatically for you when you use the ng
generate command (though you can pass an argument to the generate command to not create a
test). If you look at the codebase of our Client-Contacts-Manager application, you’ll see many
examples of these files ending spec.ts, these are the test files that the Angular CLI has created for
us.
Chapter 3: Getting Started with the Angular CLI 42

We will be going further into Unit Testing in a later chapter, but what we really want to look at is
how we can use the CLI to run these (and our future tests for us).
Again, open Terminal and navigate to our Client-Contacts-Manager folder, once there, enter the
following command:
ng test
Two things should happen; first, the Terminal window should show that it is compiling the
application, the same way the CLI compiles the application when running it in the browser.

Terminal Running ng test

In here you’ll see that it says TOTAL: 3 SUCCESS in green and Executed 3 of 3 SUCCESS, this
three of three is in reference to the three unit tests that have been created by the Angular CLI and
that these three tests have passed.

Unit tests can pass or fail, a test that is passing means the code that the test checks does
Chapter 3: Getting Started with the Angular CLI 43

what the test expects it to do. The code passes the tests checks. A failed test means the
code doesn’t pass the tests checks. We will go into this further in Chapter 10, Testing later.

The second thing you should see is the browser opens; this is caused by the Angular CLI opening the
browser to show the output of the Karma test runner the library Angular uses to run the tests. The
Angular CLI uses Karma, a popular testing framework, to go through and perform all the available
tests on the main code base. You should see the browser looking like this screenshot:

Browser Showing Test Results

This is the browser window that the Angular CLI has opened for us, showing the report Karma
generates; as you can see at the top, we have a nice green bar and this shows all our tests have
passed; if they hadn’t, it would be red. In the world of Unit tests, green is good, red is bad.
One of the things you can do is have two Terminal windows open or one window divided into two
sections if your Terminal of choice does that; in one window have the Angular CLI running the app
and in the other have the Angular CLI running the ng test command. This will lead to your tests
Exploring the Variety of Random
Documents with Different Content
Palæstra, 69 sq., 78 sq.
Pantheism, 136.
Parmenides, 24.
Parthenon, 24, 106.
Pedagogical State, 172 sqq.
Pedagogue, 68.
Peleus, 7.
Pentathlon, 88.
Pericles, 105 sqq.
Perioikoi, 44.
Periods of Greek Education, 26 sqq.
Persian Education, 115 sqq.
Personality, 202.
Pherecydes, 53.
Phiditia, 44.
Philolaus, 39.
Philosophy, Rise of, 22.
Philosophy and Individualism, 93 sqq.
Physical Culture, 189.
Physicians in Homer, 17.
Pindar, 39.
Pisistratus, 35, 98, 178.
Plato, 29, 112, 133 sqq., 134, 136, 137, 142.
Play, 66, 181 sqq.
Plotinus, 29, 225 sqq., 228 sqq.
Poetesses, 21.
Poetry, Value of, for Education, 73 sqq.
"Professional," Meaning of, 195.
Prometheia, 24.
Proxenus of Atarneus, 155.
Purgation, 7, 76.
Pythagoras, 29, 52 sqq., 149.
Pythias, 156.

Q
Quadrivium, 144, 198.
Quintilian, 29, 214 sqq.

R
Reading, 75.
Rhapsodes, 23.
Rhetorical Schools, 209, 217.
Roman Education, 216 sqq.
Roman Period, 27.
Ruling and Ruled, 176.
Running, 79.

S
School Education in Athens, 67.
" Buildings " " 69.
" Rooms " " 77.
Scipio Africanus, 216.
Singing, 75.
Slaves, 12.
Social Life in Greece, 18.
Socrates, 24, 107 sqq.
Socratic Method, 109.
Solon, and his Laws, 68, 98.
Soothsayers in Homer, 17.
Sophists, 23, 100 sq.
Spartan Education, 41, 43 sqq.
Spartan Girls, 49.
" Government, 44.
" Ideal, 42.
" Mercilessness, 45, 50.
" Women, 44.
Stagira, 155 sq.
State, Meaning of Term, 174.
State as a School, 91.
Stilo, Lucius Ælius Præconinus, 217.
Stoics, 210.
Supercivic Man, 136, 234.

T
Theban Education, 28.
Themistes, 17.
Theories of Education, 28.
Therapeuts, 212.
Thomas Aquinas, 165.
Thucydides' Daughter, 37.
Tragedy, 84.
Trivium, 144, 198.

U
University Education, 90.
" of Alexandria, 212.
" of Athens, 211.

W
Wilhelm Meister, 173.
Wingless Victory, 63.
Wisdom, the Ideal of Athens, 63.
Women, Education of, 49, 124.
Worth, 16, 48.
Worth, Aristotle's Pæan to, 4.
Wrestling, 81 sqq.
Writing, 75.

X
Xenophon, 29, 113, 114 sqq.
" Memoirs of Socrates, 123.
" Œconomics, 124.
" on Female Education, 124 sqq.

Typography by J.S. Cushing & Co., Boston, U.S.A.


Presswork by Berwick & Smith, Boston, U.S.A.
TRANSCRIBER'S NOTES
Corrections from the errata list on p. 2 have been incorporated into the text.
The variant spellings "freeborn" and "free-born", "Staatspædagogik" and
"Staatspaedagogik", "subdivided" and "sub-divided" are used in this text.
The abbreviations B.C. and A.D. sometimes precede their date, sometimes follow it.

Amendments to the text have been made as follows:


p. 21: "Spata" amended to "Sparta".
p. 63: "civilizaton" amended to "civilization".
p. 74: "partiotism" amended to "patriotism".
p. 78: "neans" amended to "means".
p. 78: "humane" amended to "human".
p. 85: "pantomine" amended to "pantomime".
p. 186: "sufficent" amended to "sufficient".
p. 188: quotation mark deleted after "not being universal."
p. 218: b.c. amended to a.d.
p. 227: "fourtieth" amended to "fortieth".
p. 243: "Grammer" amended to "Grammar".
p. 246: full stop added after "Mathematics".
p. 246: extra "the" deleted from "the following century".

Greek:
On p. 22 αἴτια has not been changed to αἰτία (as in LSJ) as it may be an acceptable
alternative form.
Similarly on p. 223 παιδοτρίβεια has not been changed to παιδοτριβία (as in LSJ).
*** END OF THE PROJECT GUTENBERG EBOOK ARISTOTLE AND
ANCIENT EDUCATIONAL IDEALS ***

Updated editions will replace the previous one—the old editions


will be renamed.

Creating the works from print editions not protected by U.S.


copyright law means that no one owns a United States
copyright in these works, so the Foundation (and you!) can copy
and distribute it in the United States without permission and
without paying copyright royalties. Special rules, set forth in the
General Terms of Use part of this license, apply to copying and
distributing Project Gutenberg™ electronic works to protect the
PROJECT GUTENBERG™ concept and trademark. Project
Gutenberg is a registered trademark, and may not be used if
you charge for an eBook, except by following the terms of the
trademark license, including paying royalties for use of the
Project Gutenberg trademark. If you do not charge anything for
copies of this eBook, complying with the trademark license is
very easy. You may use this eBook for nearly any purpose such
as creation of derivative works, reports, performances and
research. Project Gutenberg eBooks may be modified and
printed and given away—you may do practically ANYTHING in
the United States with eBooks not protected by U.S. copyright
law. Redistribution is subject to the trademark license, especially
commercial redistribution.

START: FULL LICENSE


THE FULL PROJECT GUTENBERG LICENSE
PLEASE READ THIS BEFORE YOU DISTRIBUTE OR USE THIS WORK

To protect the Project Gutenberg™ mission of promoting the


free distribution of electronic works, by using or distributing this
work (or any other work associated in any way with the phrase
“Project Gutenberg”), you agree to comply with all the terms of
the Full Project Gutenberg™ License available with this file or
online at www.gutenberg.org/license.

Section 1. General Terms of Use and


Redistributing Project Gutenberg™
electronic works
1.A. By reading or using any part of this Project Gutenberg™
electronic work, you indicate that you have read, understand,
agree to and accept all the terms of this license and intellectual
property (trademark/copyright) agreement. If you do not agree
to abide by all the terms of this agreement, you must cease
using and return or destroy all copies of Project Gutenberg™
electronic works in your possession. If you paid a fee for
obtaining a copy of or access to a Project Gutenberg™
electronic work and you do not agree to be bound by the terms
of this agreement, you may obtain a refund from the person or
entity to whom you paid the fee as set forth in paragraph 1.E.8.

1.B. “Project Gutenberg” is a registered trademark. It may only


be used on or associated in any way with an electronic work by
people who agree to be bound by the terms of this agreement.
There are a few things that you can do with most Project
Gutenberg™ electronic works even without complying with the
full terms of this agreement. See paragraph 1.C below. There
are a lot of things you can do with Project Gutenberg™
electronic works if you follow the terms of this agreement and
help preserve free future access to Project Gutenberg™
electronic works. See paragraph 1.E below.
1.C. The Project Gutenberg Literary Archive Foundation (“the
Foundation” or PGLAF), owns a compilation copyright in the
collection of Project Gutenberg™ electronic works. Nearly all the
individual works in the collection are in the public domain in the
United States. If an individual work is unprotected by copyright
law in the United States and you are located in the United
States, we do not claim a right to prevent you from copying,
distributing, performing, displaying or creating derivative works
based on the work as long as all references to Project
Gutenberg are removed. Of course, we hope that you will
support the Project Gutenberg™ mission of promoting free
access to electronic works by freely sharing Project Gutenberg™
works in compliance with the terms of this agreement for
keeping the Project Gutenberg™ name associated with the
work. You can easily comply with the terms of this agreement
by keeping this work in the same format with its attached full
Project Gutenberg™ License when you share it without charge
with others.

1.D. The copyright laws of the place where you are located also
govern what you can do with this work. Copyright laws in most
countries are in a constant state of change. If you are outside
the United States, check the laws of your country in addition to
the terms of this agreement before downloading, copying,
displaying, performing, distributing or creating derivative works
based on this work or any other Project Gutenberg™ work. The
Foundation makes no representations concerning the copyright
status of any work in any country other than the United States.

1.E. Unless you have removed all references to Project


Gutenberg:

1.E.1. The following sentence, with active links to, or other


immediate access to, the full Project Gutenberg™ License must
appear prominently whenever any copy of a Project
Gutenberg™ work (any work on which the phrase “Project
Gutenberg” appears, or with which the phrase “Project
Gutenberg” is associated) is accessed, displayed, performed,
viewed, copied or distributed:

This eBook is for the use of anyone anywhere in the United


States and most other parts of the world at no cost and
with almost no restrictions whatsoever. You may copy it,
give it away or re-use it under the terms of the Project
Gutenberg License included with this eBook or online at
www.gutenberg.org. If you are not located in the United
States, you will have to check the laws of the country
where you are located before using this eBook.

1.E.2. If an individual Project Gutenberg™ electronic work is


derived from texts not protected by U.S. copyright law (does not
contain a notice indicating that it is posted with permission of
the copyright holder), the work can be copied and distributed to
anyone in the United States without paying any fees or charges.
If you are redistributing or providing access to a work with the
phrase “Project Gutenberg” associated with or appearing on the
work, you must comply either with the requirements of
paragraphs 1.E.1 through 1.E.7 or obtain permission for the use
of the work and the Project Gutenberg™ trademark as set forth
in paragraphs 1.E.8 or 1.E.9.

1.E.3. If an individual Project Gutenberg™ electronic work is


posted with the permission of the copyright holder, your use and
distribution must comply with both paragraphs 1.E.1 through
1.E.7 and any additional terms imposed by the copyright holder.
Additional terms will be linked to the Project Gutenberg™
License for all works posted with the permission of the copyright
holder found at the beginning of this work.

1.E.4. Do not unlink or detach or remove the full Project


Gutenberg™ License terms from this work, or any files
containing a part of this work or any other work associated with
Project Gutenberg™.

1.E.5. Do not copy, display, perform, distribute or redistribute


this electronic work, or any part of this electronic work, without
prominently displaying the sentence set forth in paragraph 1.E.1
with active links or immediate access to the full terms of the
Project Gutenberg™ License.

1.E.6. You may convert to and distribute this work in any binary,
compressed, marked up, nonproprietary or proprietary form,
including any word processing or hypertext form. However, if
you provide access to or distribute copies of a Project
Gutenberg™ work in a format other than “Plain Vanilla ASCII” or
other format used in the official version posted on the official
Project Gutenberg™ website (www.gutenberg.org), you must,
at no additional cost, fee or expense to the user, provide a copy,
a means of exporting a copy, or a means of obtaining a copy
upon request, of the work in its original “Plain Vanilla ASCII” or
other form. Any alternate format must include the full Project
Gutenberg™ License as specified in paragraph 1.E.1.

1.E.7. Do not charge a fee for access to, viewing, displaying,


performing, copying or distributing any Project Gutenberg™
works unless you comply with paragraph 1.E.8 or 1.E.9.

1.E.8. You may charge a reasonable fee for copies of or


providing access to or distributing Project Gutenberg™
electronic works provided that:

• You pay a royalty fee of 20% of the gross profits you derive
from the use of Project Gutenberg™ works calculated using the
method you already use to calculate your applicable taxes. The
fee is owed to the owner of the Project Gutenberg™ trademark,
but he has agreed to donate royalties under this paragraph to
the Project Gutenberg Literary Archive Foundation. Royalty
payments must be paid within 60 days following each date on
which you prepare (or are legally required to prepare) your
periodic tax returns. Royalty payments should be clearly marked
as such and sent to the Project Gutenberg Literary Archive
Foundation at the address specified in Section 4, “Information
about donations to the Project Gutenberg Literary Archive
Foundation.”

• You provide a full refund of any money paid by a user who


notifies you in writing (or by e-mail) within 30 days of receipt
that s/he does not agree to the terms of the full Project
Gutenberg™ License. You must require such a user to return or
destroy all copies of the works possessed in a physical medium
and discontinue all use of and all access to other copies of
Project Gutenberg™ works.

• You provide, in accordance with paragraph 1.F.3, a full refund of


any money paid for a work or a replacement copy, if a defect in
the electronic work is discovered and reported to you within 90
days of receipt of the work.

• You comply with all other terms of this agreement for free
distribution of Project Gutenberg™ works.

1.E.9. If you wish to charge a fee or distribute a Project


Gutenberg™ electronic work or group of works on different
terms than are set forth in this agreement, you must obtain
permission in writing from the Project Gutenberg Literary
Archive Foundation, the manager of the Project Gutenberg™
trademark. Contact the Foundation as set forth in Section 3
below.

1.F.

1.F.1. Project Gutenberg volunteers and employees expend


considerable effort to identify, do copyright research on,
transcribe and proofread works not protected by U.S. copyright
law in creating the Project Gutenberg™ collection. Despite these
efforts, Project Gutenberg™ electronic works, and the medium
on which they may be stored, may contain “Defects,” such as,
but not limited to, incomplete, inaccurate or corrupt data,
transcription errors, a copyright or other intellectual property
infringement, a defective or damaged disk or other medium, a
computer virus, or computer codes that damage or cannot be
read by your equipment.

1.F.2. LIMITED WARRANTY, DISCLAIMER OF DAMAGES - Except


for the “Right of Replacement or Refund” described in
paragraph 1.F.3, the Project Gutenberg Literary Archive
Foundation, the owner of the Project Gutenberg™ trademark,
and any other party distributing a Project Gutenberg™ electronic
work under this agreement, disclaim all liability to you for
damages, costs and expenses, including legal fees. YOU AGREE
THAT YOU HAVE NO REMEDIES FOR NEGLIGENCE, STRICT
LIABILITY, BREACH OF WARRANTY OR BREACH OF CONTRACT
EXCEPT THOSE PROVIDED IN PARAGRAPH 1.F.3. YOU AGREE
THAT THE FOUNDATION, THE TRADEMARK OWNER, AND ANY
DISTRIBUTOR UNDER THIS AGREEMENT WILL NOT BE LIABLE
TO YOU FOR ACTUAL, DIRECT, INDIRECT, CONSEQUENTIAL,
PUNITIVE OR INCIDENTAL DAMAGES EVEN IF YOU GIVE
NOTICE OF THE POSSIBILITY OF SUCH DAMAGE.

1.F.3. LIMITED RIGHT OF REPLACEMENT OR REFUND - If you


discover a defect in this electronic work within 90 days of
receiving it, you can receive a refund of the money (if any) you
paid for it by sending a written explanation to the person you
received the work from. If you received the work on a physical
medium, you must return the medium with your written
explanation. The person or entity that provided you with the
defective work may elect to provide a replacement copy in lieu
of a refund. If you received the work electronically, the person
or entity providing it to you may choose to give you a second
opportunity to receive the work electronically in lieu of a refund.
If the second copy is also defective, you may demand a refund
in writing without further opportunities to fix the problem.

1.F.4. Except for the limited right of replacement or refund set


forth in paragraph 1.F.3, this work is provided to you ‘AS-IS’,
WITH NO OTHER WARRANTIES OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO WARRANTIES OF
MERCHANTABILITY OR FITNESS FOR ANY PURPOSE.

1.F.5. Some states do not allow disclaimers of certain implied


warranties or the exclusion or limitation of certain types of
damages. If any disclaimer or limitation set forth in this
agreement violates the law of the state applicable to this
agreement, the agreement shall be interpreted to make the
maximum disclaimer or limitation permitted by the applicable
state law. The invalidity or unenforceability of any provision of
this agreement shall not void the remaining provisions.

1.F.6. INDEMNITY - You agree to indemnify and hold the


Foundation, the trademark owner, any agent or employee of the
Foundation, anyone providing copies of Project Gutenberg™
electronic works in accordance with this agreement, and any
volunteers associated with the production, promotion and
distribution of Project Gutenberg™ electronic works, harmless
from all liability, costs and expenses, including legal fees, that
arise directly or indirectly from any of the following which you
do or cause to occur: (a) distribution of this or any Project
Gutenberg™ work, (b) alteration, modification, or additions or
deletions to any Project Gutenberg™ work, and (c) any Defect
you cause.

Section 2. Information about the Mission


of Project Gutenberg™
Project Gutenberg™ is synonymous with the free distribution of
electronic works in formats readable by the widest variety of
computers including obsolete, old, middle-aged and new
computers. It exists because of the efforts of hundreds of
volunteers and donations from people in all walks of life.

Volunteers and financial support to provide volunteers with the


assistance they need are critical to reaching Project
Gutenberg™’s goals and ensuring that the Project Gutenberg™
collection will remain freely available for generations to come. In
2001, the Project Gutenberg Literary Archive Foundation was
created to provide a secure and permanent future for Project
Gutenberg™ and future generations. To learn more about the
Project Gutenberg Literary Archive Foundation and how your
efforts and donations can help, see Sections 3 and 4 and the
Foundation information page at www.gutenberg.org.

Section 3. Information about the Project


Gutenberg Literary Archive Foundation
The Project Gutenberg Literary Archive Foundation is a non-
profit 501(c)(3) educational corporation organized under the
laws of the state of Mississippi and granted tax exempt status
by the Internal Revenue Service. The Foundation’s EIN or
federal tax identification number is 64-6221541. Contributions
to the Project Gutenberg Literary Archive Foundation are tax
deductible to the full extent permitted by U.S. federal laws and
your state’s laws.

The Foundation’s business office is located at 809 North 1500


West, Salt Lake City, UT 84116, (801) 596-1887. Email contact
links and up to date contact information can be found at the
Foundation’s website and official page at
www.gutenberg.org/contact
Section 4. Information about Donations to
the Project Gutenberg Literary Archive
Foundation
Project Gutenberg™ depends upon and cannot survive without
widespread public support and donations to carry out its mission
of increasing the number of public domain and licensed works
that can be freely distributed in machine-readable form
accessible by the widest array of equipment including outdated
equipment. Many small donations ($1 to $5,000) are particularly
important to maintaining tax exempt status with the IRS.

The Foundation is committed to complying with the laws


regulating charities and charitable donations in all 50 states of
the United States. Compliance requirements are not uniform
and it takes a considerable effort, much paperwork and many
fees to meet and keep up with these requirements. We do not
solicit donations in locations where we have not received written
confirmation of compliance. To SEND DONATIONS or determine
the status of compliance for any particular state visit
www.gutenberg.org/donate.

While we cannot and do not solicit contributions from states


where we have not met the solicitation requirements, we know
of no prohibition against accepting unsolicited donations from
donors in such states who approach us with offers to donate.

International donations are gratefully accepted, but we cannot


make any statements concerning tax treatment of donations
received from outside the United States. U.S. laws alone swamp
our small staff.

Please check the Project Gutenberg web pages for current


donation methods and addresses. Donations are accepted in a
number of other ways including checks, online payments and
credit card donations. To donate, please visit:
www.gutenberg.org/donate.

Section 5. General Information About


Project Gutenberg™ electronic works
Professor Michael S. Hart was the originator of the Project
Gutenberg™ concept of a library of electronic works that could
be freely shared with anyone. For forty years, he produced and
distributed Project Gutenberg™ eBooks with only a loose
network of volunteer support.

Project Gutenberg™ eBooks are often created from several


printed editions, all of which are confirmed as not protected by
copyright in the U.S. unless a copyright notice is included. Thus,
we do not necessarily keep eBooks in compliance with any
particular paper edition.

Most people start at our website which has the main PG search
facility: www.gutenberg.org.

This website includes information about Project Gutenberg™,


including how to make donations to the Project Gutenberg
Literary Archive Foundation, how to help produce our new
eBooks, and how to subscribe to our email newsletter to hear
about new eBooks.
Welcome to our website – the perfect destination for book lovers and
knowledge seekers. We believe that every book holds a new world,
offering opportunities for learning, discovery, and personal growth.
That’s why we are dedicated to bringing you a diverse collection of
books, ranging from classic literature and specialized publications to
self-development guides and children's books.

More than just a book-buying platform, we strive to be a bridge


connecting you with timeless cultural and intellectual values. With an
elegant, user-friendly interface and a smart search system, you can
quickly find the books that best suit your interests. Additionally,
our special promotions and home delivery services help you save time
and fully enjoy the joy of reading.

Join us on a journey of knowledge exploration, passion nurturing, and


personal growth every day!

ebookbell.com

You might also like