You are previewing AngularJS: Up and Running.
O'Reilly logo
AngularJS: Up and Running

Book Description

If you want to get started with AngularJS, either as a side project, an additional tool, or for your main work, this practical guide teaches you how to use this meta-framework step-by-step, from the basics to advanced concepts. By the end of the book, you’ll understand how to develop a large, maintainable, and performant application with AngularJS.

Table of Contents

  1. Introduction
    1. Who Should Read This Book
    2. Why We 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. Safari® Books Online
    9. How to Contact Us
    10. Acknowledgments
  2. 1. Introducing AngularJS
    1. Introducing AngularJS
      1. What Is MVC (Model-View-Controller)?
      2. AngularJS Benefits
      3. The AngularJS Philosophy
    2. Starting Out with AngularJS
      1. What Backend Do I Need?
      2. Does My Entire Application Need to Be an AngularJS App?
      3. A Basic AngularJS Application
      4. AngularJS Hello World
    3. Conclusion
  3. 2. Basic AngularJS Directives and Controllers
    1. AngularJS Modules
    2. Creating Our First Controller
    3. Working with and Displaying Arrays
    4. More Directives
    5. Working with ng-repeat
      1. ng-repeat Over an Object
      2. Helper Variables in ng-repeat
      3. Track by ID
      4. ng-repeat Across Multiple HTML Elements
    6. Conclusion
  4. 3. Unit Testing in AngularJS
    1. Unit Testing: What and Why?
    2. Introduction to Karma
      1. Karma Plugins
      2. Explaining the Karma Config
      3. Generating the Karma Config
    3. Jasmine: Spec Style of Testing
      1. Jasmine Syntax
      2. Useful Jasmine Matchers
    4. Writing a Unit Test for Our Controller
    5. Running the Unit Test
    6. Conclusion
  5. 4. Forms, Inputs, and Services
    1. Working with ng-model
    2. Working with Forms
    3. Leverage Data-Binding and Models
    4. Form Validation and States
    5. Error Handling with Forms
      1. Displaying Error Messages
      2. Styling Forms and States
    6. Nested Forms with ng-form
    7. Other Form Controls
      1. Textareas
      2. Checkboxes
      3. Radio Buttons
      4. Combo Boxes/Drop-Downs
    8. Conclusion
  6. 5. All About AngularJS Services
    1. AngularJS Services
      1. Why Do We Need AngularJS Services?
      2. Services Versus Controllers
      3. Dependency Injection in AngularJS
      4. Using Built-In AngularJS Services
      5. Order of Injection
      6. Common AngularJS Services
    2. Creating Our Own AngularJS Service
      1. Creating a Simple AngularJS Service
      2. The Difference Between Factory, Service, and Provider
    3. Conclusion
  7. 6. Server Communication Using $http
    1. Fetching Data with $http Using GET
      1. A Deep Dive into Promises
      2. Propagating Success and Error
      3. The $q Service
      4. Making POST Requests with $http
      5. $http API
      6. Configuration
    2. Advanced $http
      1. Configuring $http Defaults
      2. Interceptors
      3. Best Practices
    3. Conclusion
  8. 7. Unit Testing Services and XHRs
    1. Dependency Injection in Our Unit Tests
      1. State Across Unit Tests
      2. Mocking Out Services
      3. Spies
    2. Unit Testing Server Calls
      1. Integration-Level Unit Tests
    3. Conclusion
  9. 8. Working with Filters
    1. What Are AngularJS Filters?
      1. Using AngularJS Filters
      2. Common AngularJS Filters
      3. Using Filters in Controllers and Services
    2. Creating AngularJS Filters
    3. Things to Remember About Filters
    4. Conclusion
  10. 9. Unit Testing Filters
    1. The Filter Under Test
    2. Testing the timeAgo Filter
    3. Conclusion
  11. 10. Routing Using ngRoute
    1. Routing in a Single-Page Application
    2. Using ngRoute
    3. Routing Options
      1. Using Resolves for Pre-Route Checks
      2. Using the $routeParams Service
      3. Things to Watch Out For
      4. A Full AngularJS Routing Example
    4. Additional Configuration
      1. HTML5 Mode
      2. SEO with AngularJS
      3. Analytics with AngularJS
    5. Alternatives: ui-router
    6. Conclusion
  12. 11. Directives
    1. What Are Directives?
    2. Alternatives to Custom Directives
      1. ng-include
      2. Limitations of ng-include
      3. ng-switch
    3. Understanding the Basic Options
      1. Creating a Directive
      2. Template/Template URL
      3. Restrict
      4. The link Function
      5. Scope
      6. Replace
    4. Conclusion
  13. 12. Unit Testing Directives
    1. Steps Involved in Testing a Directive
    2. The Stock Widget Directive
    3. Setting Up Our Directive Unit Test
    4. Other Considerations
    5. Conclusion
  14. 13. Advanced Directives
    1. Life Cycles in AngularJS
      1. AngularJS Life Cycle
      2. The Digest Cycle
      3. Directive Life Cycle
    2. Transclusions
      1. Basic Transclusion
      2. Advanced Transclusion
    3. Directive Controllers and require
      1. require Options
      2. Input Directives with ng-model
      3. Custom Validators
    4. Compile
    5. Priority and Terminal
    6. Third-Party Integration
    7. Best Practices
      1. Scopes
      2. Clean Up and Destroy
      3. Watchers
      4. $apply (and $digest)
    8. Conclusion
  15. 14. End-to-End Testing
    1. The Need for Protractor
    2. Initial Setup
    3. Protractor Configuration
    4. An End-to-End Test
    5. Considerations
    6. Conclusion
  16. 15. Guidelines and Best Practices
    1. Testing
      1. Test-Driven Development
      2. Variety of Tests
      3. When to Run Tests
    2. Project Structure
      1. Best Practices
      2. Directory Structure
      3. Third-Party Libraries
      4. Starting Point
    3. Build
      1. Grunt
      2. Serve a Single JavaScript File
      3. Minification
      4. ng-templates
    4. Best Practices
      1. General
      2. Services
      3. Controllers
      4. Directives
      5. Filters
    5. Tools and Libraries
      1. Batarang
      2. WebStorm
      3. Optional Modules
    6. Conclusion
  17. Index
  18. Colophon
  19. Copyright