Angular: Up and Running

Book description

If you’re familiar with JavaScript, this hands-on guide will quickly get you up to speed on the Angular framework for building high-performance web-based desktop, mobile, and single-page applications. Initially dubbed Angular 2, this version is a complete rewrite from the same team that built the initial version of AngularJS. Developers familiar with that earlier version will also find this book to be a valuable resource.

Author Shyam Seshadri takes you step-by-step through Angular’s core building blocks in detail. You’ll start by creating a simple Angular application before diving into Angular components, services, server calls, routing, and production requirements. By the end of the book, you’ll be ready to use Angular for your own applications.

  • Set up your development environment to build Angular applications rapidly
  • Use Angular directives to construct common functionality for your application
  • Create and test Angular components for building effective user interfaces
  • Manage user input by building template-driven and reactive forms
  • Understand when to use built-in Angular services and when and how to create your own
  • Make HTTP calls and handle use cases that surface when working with servers
  • Use Angular’s routing module to encapsulate various pages and pieces using a different route
  • Build an Angular application for production and learn how to deploy a performant Angular application

Publisher resources

View/Submit Errata

Table of contents

  1. Introduction
    1. Who Should Read This Book
    2. Why I Wrote This Book
    3. A Word on Web Application Development Today
    4. Navigating This Book
    5. Online Resources
    6. Conventions Used in This Book
    7. Using Code Examples
    8. O’Reilly Safari
    9. How to Contact Us
    10. Acknowledgments
  2. 1. Introducing Angular
    1. Why Angular
    2. What This Book Will Not Cover
    3. Getting Started with Your Development Environment
      1. Node.js
      2. TypeScript
      3. Angular CLI
      4. Getting the Codebase
    4. Conclusion
  3. 2. Hello Angular
    1. Starting Your First Angular Project
    2. Understanding the Angular CLI
      1. Running the Application
    3. Basics of an Angular Application
      1. Root HTML—index.html
      2. The Entry Point—main.ts
      3. Main Module—app.module.ts
      4. Root Component—AppComponent
    4. Creating a Component
      1. Steps in Creating New Components
      2. Using Our New Component
      3. Understanding Data Binding
      4. Understanding Property Binding
      5. Understanding Event Binding
      6. Using Models for Cleaner Code
    5. Conclusion
    6. Exercise
  4. 3. Useful Built-In Angular Directives
    1. Directives and Components
    2. Built-In Attribute Directives
      1. NgClass
      2. NgStyle
      3. Alternative Class and Style Binding Syntax
    3. Built-In Structural Directives
      1. NgIf
      2. NgFor
      3. NgSwitch
      4. Multiple Sibling Structural Directives
    4. Conclusion
    5. Exercise
  5. 4. Understanding and Using Angular Components
    1. Components—A Recap
    2. Defining a Component
      1. Selector
      2. Template
      3. Styles
      4. Style Encapsulation
      5. Others
    3. Components and Modules
    4. Input and Output
      1. Input
      2. Output
      3. Change Detection
    5. Component Lifecycle
      1. Interfaces and Functions
    6. View Projection
    7. Conclusion
    8. Exercise
  6. 5. Testing Angular Components
    1. Why Unit Test?
    2. Testing and Angular
    3. The Test Setup
      1. Karma Config
      2. test.ts
    4. Writing Unit Tests
      1. An Isolated Unit Test
      2. Running the Tests
      3. Writing an Angular-Aware Unit Test
      4. Testing Component Interactions
    5. Debugging
    6. Conclusion
    7. Exercise
  7. 6. Working with Template-Driven Forms
    1. Template-Driven Forms
      1. Setting Up Forms
      2. Alternative to ngModel—Event and Property Binding
      3. ngModel
      4. A Complete Form
      5. Control State
      6. Control Validity
    2. Working with FormGroups
    3. Conclusion
    4. Exercise
  8. 7. Working with Reactive Forms
    1. Reactive Forms
      1. Understanding the Differences
    2. Using Reactive Forms
      1. Form Controls
      2. Form Groups
      3. Form Builders
    3. Form Data
      1. Control State, Validity, and Error Messages
      2. Form and Data Model
    4. FormArrays
    5. Conclusion
    6. Exercise
  9. 8. Angular Services
    1. What Are Angular Services?
    2. Creating Our Own Angular Service
      1. Digging into the Example
      2. An Introduction to Dependency Injection
      3. Angular and Dependency Injection
    3. RxJS and Observables: Moving to Asynchronous Operations
    4. Conclusion
    5. Exercise
  10. 9. Making HTTP Calls in Angular
    1. Introducing HttpClient
      1. Server Setup
      2. Using HttpClientModule
      3. Making HTTP GET/POST Calls
    2. Advanced HTTP
      1. Options—Headers/Params
      2. Options—Observe/Response Type
      3. Interceptors
    3. Advanced Observables
    4. Conclusion
    5. Exercise
  11. 10. Unit Testing Services
    1. How to Unit Test Services
    2. Testing Components with a Service Dependency
      1. Testing Components with a Real Service
      2. Testing Components with a Mock Service
      3. Testing Components with a Fake Service
    3. Unit Testing Async
    4. Unit Testing HTTP
    5. Conclusion
    6. Exercise
  12. 11. Routing in Angular
    1. Setting Up Angular Routing
      1. Server Setup
      2. Starting Codebase
      3. Importing the Router Module
      4. Displaying the Route Contents
      5. Navigating Within the Application
      6. Wildcards and Defaults
    2. Common Routing Requirements
      1. Required Route Params
      2. Navigating in Your Application
      3. Optional Route Params
    3. Route Guards
      1. Authenticated-Only Routes
      2. Preventing Unload
      3. Preloading Data Using Resolve
    4. Conclusion
    5. Exercise
  13. 12. Productionizing an Angular App
    1. Building for Production
      1. Production Build
      2. Ahead-of-Time (AOT) Compilation and Build Optimizer
      3. Base Href
      4. Deploying an Angular Application
    2. Other Concerns
      1. Caching
      2. API/Server Calls and CORS
      3. Different Environments
      4. Handling Deep-Linking
      5. Lazy Loading
      6. Server-Side Rendering and Handling SEO
    3. Conclusion
  14. Index

Product information

  • Title: Angular: Up and Running
  • Author(s): Shyam Seshadri
  • Release date: June 2018
  • Publisher(s): O'Reilly Media, Inc.
  • ISBN: 9781491999837