Book Image

Essential Angular

By : Victor Savkin, Jeff Cross
Book Image

Essential Angular

By: Victor Savkin, Jeff Cross

Overview of this book

Essential Angular is a concise, complete overview of the key aspects of Angular, written by two Angular core contributors. The book covers the framework's mental model, its API, and the design principles behind it. This book is fully up to date with the latest release of Angular. Essential Angular gives you a strong foundation in the core Angular technology. It will help you put all the concepts into the right places so you will have a good understanding of why the framework is the way it is. Read this book after you have toyed around with the framework, but before you embark on writing your first serious Angular application. This book covers concepts such as the differences between Just-In-Time (JIT) and Ahead-Of-Time (AOT) compilation in Angular, alongside NgModules, components and directives. It also goes into detail on Dependency Injection and Change Detection: essential skills for Angular developers to master. The book finishes with a look at testing, and how to integrate different testing methodologies in your Angular code.
Table of Contents (11 chapters)

Dependency Injection

The idea behind dependency injection is very simple. If you have a component that depends on a service, you do not create that service yourself. Instead, you request one in the constructor, and the framework will provide you one. By doing so you can depend on interfaces rather than concrete types. This leads to more decoupled code, which enables testability, and other great things.

Angular comes with a dependency injection system. To see how it can be used, let's look at the following component, which renders a list of talks using the for directive:

selector: 'talks-cmp',
template: `
<talk *ngFor="let t of talks" [talk]="t"></talk>
class TalksCmp {
constructor() { //..get the data }

Let’s mock up a simple service that will give us the data:

class TalksAppBackend {
fetchTalks() {