HAPPY BOOKSGIVING
Use code BOOKSGIVING during checkout to save 40%-55% on books and eBooks. Shop now.
This eBook includes the following formats, accessible from your Account page after purchase:
EPUB The open industry format known for its reflowable content and usability on supported mobile devices.
PDF The popular standard, used most often with the free Acrobat® Reader® software.
This eBook requires no passwords or activation to read. We customize your eBook by discreetly watermarking it with your name, making it uniquely yours.
Also available in other formats.
Register your product to gain access to bonus material or receive a coupon.
Learning Angular, Second Edition
A Hands-On Guide to Angular 2 and Angular 4
Learning Angular teaches modern application development with Angular 2 and Angular 4. It begins with the basics of Angular and the technologies and techniques used throughout the book, such as key features of TypeScript, newer ES6 syntax and concepts, and details about the tools needed to write professional Angular applications.
The reader will next build an Angular application from scratch while learning about the primary pieces of an Angular application and see how they work together. Using lots of examples, the core parts of Angular will be introduced, such as Components, the Router, and Services.
The book also covers techniques like server-side rendering and how to incrementally add Angular 2+ features to existing AngularJS applications. Finally, the reader will gain insight into advanced skills that should be part of any professional Angular developer’s toolkit such as testing, tooling options, and performance tuning.
Contents at a Glance
Introduction
Chapter 1: Jumping into JavaScript
Chapter 2: Jumping into TypeScript
Chapter 3: Getting Started with Angular
Chapter 4: Angular Components
Chapter 5: Expressions
Chapter 6: Data Binding
Chapter 7: Built-in Directives
Chapter 8: Custom Directives
Chapter 9: Events and Change Detection
Chapter 10: Implementing Angular Services in Web Applications
Chapter 11: Creating Your Own Custom Angular Service
Chapter 12: Having Fun with Angular
Introduction 1
Chapter 1 Jumping into JavaScript 5
Setting Up a JavaScript Development Environment 5
Defining Variables 6
Understanding JavaScript Data Types 6
Using Operators 8
Arithmetic Operators 8
Assignment Operators 8
Applying Comparison and Conditional Operators 9
Implementing Looping 11
while Loops 11
do/while Loops 12
for Loops 12
for/in Loops 13
Interrupting Loops 13
Creating Functions 14
Defining Functions 14
Passing Variables to Functions 15
Returning Values from Functions 15
Using Anonymous Functions 16
Understanding Variable Scope 16
Using JavaScript Objects 17
Using Object Syntax 17
Creating Custom Defined Objects 18
Using a Prototyping Object Pattern 19
Manipulating Strings 19
Combining Strings 21
Searching a String for a Substring 21
Replacing a Word in a String 22
Splitting a String into an Array 22
Working with Arrays 22
Combining Arrays 24
Iterating Through Arrays 24
Converting an Array into a String 24
Checking Whether an Array Contains an Item 25
Adding Items to and Removing Items from Arrays 25
Adding Error Handling 25
try/catch Blocks 26
Throwing Your Own Errors 26
Using finally 27
Chapter 2 Jumping into TypeScript 29
Learning the Different Types 29
Understanding Interfaces 31
Implementing Classes 32
Class Inheritance 33
Implementing Modules 33
Understanding Functions 34
Chapter 3 Getting Started with Angular 37
Why Angular? 37
Understanding Angular 37
Modules 38
Directives 38
Data Binding 38
Dependency Injection 38
Services 39
Separation of Responsibilities 39
Adding Angular to Your Environment 39
Using the Angular CLI 40
Generating Content with the CLI 40
Creating a Basic Angular Application 41
Creating Your First Angular App 42
Understanding and Using NgModule 43
Creating the Angular Bootstrapper 44
Chapter 4 Angular Components 49
Component Configuration 49
Defining a Selector 50
Building a Template 50
Using Inline CSS and HTML in Angular Applications 51
Using Constructors 53
Using External Templates 54
Injecting Directives 56
Building a Nested Component with Dependency Injection 56
Passing in Data with Dependency Injection 58
Creating an Angular Application that Uses Inputs 59
Chapter 5 Expressions 61
Using Expressions 61
Using Basic Expressions 62
Interacting with the Component Class in Expressions 64
Using TypeScript in Angular Expressions 65
Using Pipes 68
Using Built-in Pipes 69
Using Built-in Pipes 71
Building a Custom Pipe 72
Creating a Custom Pipe 73
Chapter 6 Data Binding 75
Understanding Data Binding 75
Interpolation 76
Property Binding 77
Attribute Binding 78
Class Binding 79
Style Binding 81
Event Binding 82
Two-Way Binding 85
Chapter 7 Built-in Directives 87
Understanding Directives 87
Using Built-in Directives 87
Components Directives 88
Structural Directives 88
Attribute Directives 91
Chapter 8 Custom Directives 95
Creating a Custom Attribute Directive 95
Creating a Custom Directive with a Component 98
Chapter 9 Events and Change Detection 103
Using Browser Events 103
Emitting Custom Events 104
Emitting a Custom Event to the Parent Component Hierarchy 104
Handling Custom Events with a Listener 104
Implementing Custom Events in Nested Components 104
Deleting Data in a Parent Component from a Child Component 107
Using Observables 110
Creating an Observable Object 110
Watching for Data Changes with Observables 111
Chapter 10 Implementing Angular Services in Web Applications 115
Understanding Angular Services 115
Using the Built-in Services 115
Sending HTTP GET and PUT Requests with the http Service 116
Configuring the HTTP Request 117
Implementing the HTTP Response Callback Functions 117
Implementing a Simple JSON File and Using the http Service to Access It 118
Implementing a Simple Mock Server Using the http Service 121
Implementing a Simple Mock Server and Using the http Service to Update Items on the Server 127
Changing Views with the router Service 132
Using routes in Angular 134
Implementing a Simple Router 134
Implementing a Router with a Navigation Bar 138
Implementing a Router with Parameters 143
Chapter 11 Creating Your Own Custom Angular Services 149
Integrating Custom Services into Angular Applications 149
Adding an Angular Service to an Application 150
Implementing a Simple Application that Uses a Constant Data Service 151
Implementing a Data Transform Service 152
Implementing a Variable Data Service 156
Implementing a Service that Returns a Promise 161
Implementing a Shared Service 162
Chapter 12 Having Fun with Angular 171
Implementing an Angular Application that Uses the Animation Service 171
Implementing an Angular Application that Zooms in on Images 176
Implementing an Angular Application that Enables Drag and Drop 179
Implementing a Star Rating Angular Component 185
Index 195
We've made every effort to ensure the accuracy of this book and its companion content. Any errors that have been confirmed since this book was published can be downloaded below.