Book description
Discover over 70 recipes that provide the solutions you need to know to face every challenge in Angular 2 head on
About This Book
A first-rate reference guide with a clear structure and intuitive index that gives you as a developer exactly the information you want in exactly the way you want it
Covers no legacy material from the outdated Angular release candidates; it is up-to-date with the latest release of Angular 2.4
All the code in the book is explicitly written out, and every piece of code shown is a step towards building a simple working example
Who This Book Is For
This book is for developers who are competent with JavaScript and are looking to dive headfirst into the TypeScript edition of Angular 2. This book is also geared towards developers with experience in Angular 1 who are looking to make the transition.
What You Will Learn
Understand how to best move an Angular 1 application to Angular 2
Build a solid foundational understanding of the core elements of Angular 2 such as components, forms, and services
Gain an ability to wield complex topics such as Observables and Promises
Properly implement applications utilizing advanced topics such as dependency injection
Know how to maximize the performance of Angular 2 applications
Understand the best ways to take an Angular 2 application from TypeScript in a code editor to a fully function application served on your site
Get to know the best practices when organizing and testing a large Angular 2 application
In Detail
Angular 2 introduces an entirely new way to build applications. It wholly embraces all the newest concepts that are built into the next generation of browsers, and it cuts away all the fat and bloat from Angular 1. This book plunges directly into the heart of all the most important Angular 2 concepts for you to conquer. In addition to covering all the Angular 2 fundamentals, such as components, forms, and services, it demonstrates how the framework embraces a range of new web technologies such as ES6 and TypeScript syntax, Promises, Observables, and Web Workers, among many others.
This book covers all the most complicated Angular concepts and at the same time introduces the best practices with which to wield these powerful tools. It also covers in detail all the concepts you'll need to get you building applications faster. Oft-neglected topics such as testing and performance optimization are widely covered as well. A developer that reads through all the content in this book will have a broad and deep understanding of all the major topics in the Angular 2 universe.
Style and approach
This book follows a cookbook approach—each recipe presents a unique problem to which the solution is presented in a clear, concise, and manner step-by-step manner. With practical hands-on guidance in each and every recipe, you'll be able to get to grips with the concepts.
Table of contents
-
Angular 2 Cookbook
- Angular 2 Cookbook
- Credits
- About the Author
- About the Reviewer
- www.PacktPub.com
- Customer Feedback
- Dedication
- Preface
-
1. Strategies for Upgrading to Angular 2
- Introduction
- Componentizing directives using controllerAs encapsulation
- Migrating an application to component directives
- Implementing a basic component in AngularJS 1.5
- Normalizing service types
- Connecting Angular 1 and Angular 2 with UpgradeModule
- Downgrading Angular 2 components to Angular 1 directives with downgradeComponent
- Downgrade Angular 2 providers to Angular 1 services with downgradeInjectable
-
2. Conquering Components and Directives
- Introduction
- Using decorators to build and style a simple component
- Passing members from a parent component into a child component
- Binding to native element attributes
- Registering handlers on native browser events
- Generating and capturing custom events using EventEmitter
- Attaching behavior to DOM elements with directives
- Projecting nested content using ngContent
- Using ngFor and ngIf structural directives for model-based DOM control
- Referencing elements using template variables
- Attribute property binding
- Utilizing component lifecycle hooks
- Referencing a parent component from a child component
- Configuring mutual parent-child awareness with ViewChild and forwardRef
- Configuring mutual parent-child awareness with ContentChild and forwardRef
-
3. Building Template-Driven and Reactive Forms
- Introduction
- Implementing simple two-way data binding with ngModel
- Implementing basic field validation with a FormControl
- Bundling controls with a FormGroup
- Bundling FormControls with a FormArray
- Implementing basic forms with NgForm
- Implementing basic forms with FormBuilder and formControlName
- Creating and using a custom validator
- Creating and using a custom asynchronous validator with Promises
-
4. Mastering Promises
- Introduction
- Understanding and implementing basic Promises
- Chaining Promises and Promise handlers
- Creating Promise wrappers with Promise.resolve() and Promise.reject()
- Implementing Promise barriers with Promise.all()
- Canceling asynchronous actions with Promise.race()
- Converting a Promise into an Observable
- Converting an HTTP service Observable into a ZoneAwarePromise
-
5. ReactiveX Observables
- Introduction
- Basic utilization of Observables with HTTP
- Implementing a Publish-Subscribe model using Subjects
- Creating an Observable authentication service using BehaviorSubjects
- Building a generalized Publish-Subscribe service to replace $broadcast, $emit, and $on
- Using QueryLists and Observables to follow changes in ViewChildren
- Building a fully featured AutoComplete with Observables
-
6. The Component Router
- Introduction
- Setting up an application to support simple routes
- Navigating with routerLinks
- Navigating with the Router service
- Selecting a LocationStrategy for path construction
- Building stateful route behavior with RouterLinkActive
- Implementing nested views with route parameters and child routes
- Working with matrix URL parameters and routing arrays
- Adding route authentication controls with route guards
- 7. Services, Dependency Injection, and NgModule
-
8. Application Organization and Management
- Introduction
- Composing package.json for a minimum viable Angular 2 application
- Configuring TypeScript for a minimum viable Angular 2 application
- Performing in-browser transpilation with SystemJS
- Composing application files for a minimum viable Angular 2 application
- Migrating the minimum viable application to Webpack bundling
- Incorporating shims and polyfills into Webpack
- HTML generation with html-webpack-plugin
- Setting up an application with Angular CLI
-
9. Angular 2 Testing
- Introduction
- Creating a minimum viable unit test suite with Karma, Jasmine, and TypeScript
- Writing a minimum viable unit test suite for a simple component
- Writing a minimum viable end-to-end test suite for a simple application
- Unit testing a synchronous service
- Unit testing a component with a service dependency using stubs
- Unit testing a component with a service dependency using spies
-
10. Performance and Advanced Concepts
- Introduction
- Understanding and properly utilizing enableProdMode with pure and impure pipes
- Working with zones outside Angular
- Listening for NgZone events
- Execution outside the Angular zone
- Configuring components to use explicit change detection with OnPush
- Configuring ViewEncapsulation for maximum efficiency
- Configuring the Angular 2 Renderer to use web workers
- Configuring applications to use ahead-of-time compilation
- Configuring an application to use lazy loading
Product information
- Title: Angular 2 Cookbook
- Author(s):
- Release date: January 2017
- Publisher(s): Packt Publishing
- ISBN: 9781785881923
You might also like
book
Building Large-Scale Web Applications with Angular
A definitive guide on frontend development with Angular from design to deployment Key Features Develop web …
book
Angular 6 for Enterprise-Ready Web Applications
A hands-on guide with a minimalist and flexible approach that enables quick learning and rapid delivery …
book
Angular 5 Projects: Learn to Build Single Page Web Applications Using 70+ Projects
Learn to build single page web apps using Angular 5 and TypeScript by working through 70+ …
book
Switching to Angular - Third Edition
Switching to Angular, Third Edition is the go-to book to align and get started with the …