Free Sample
+ Collection

AngularJS Services

Jim Lavin

Design, build, and test services to create a foundation for your AngularJS applications
RRP $16.99
RRP $26.99
Print + eBook

Want this title & more?

$12.99 p/month

Subscribe to PacktLib

Enjoy full and instant access to over 2000 books and videos – you’ll find everything you need to stay ahead of the curve and make sure you can always get the job done.

Book Details

ISBN 139781783983568
Paperback152 pages

About This Book

  • Understand how services are a vital component of the AngularJS framework and how leveraging services can benefit your application
  • Design and structure your AngularJS services and learn the best practices used in designing AngularJS services
  • Effectively write, test, and finally deploy your application

Who This Book Is For

If you are an intermediate JavaScript developer who is looking to enhance your understanding of single-page web application development with a focus on AngularJS services, then this book is for you.

Table of Contents

Chapter 1: The Need for Services
AngularJS best practices
Responsibilities of controllers
Responsibilities of directives
Responsibilities of services
Chapter 2: Designing Services
Measure twice, and cut once
Defining your service's interface
Designing for testability
Services, factories, and providers
Structuring your service in code
Configuring your service
Chapter 3: Testing Services
The basics of a test scenario
Loading your modules in a scenario
Mocking data
Mocking services
Mocking services with Jasmine spies
Handling dependencies that return promises
Mocking backend communications
Mocking timers
Chapter 4: Handling Cross-cutting Concerns
Communicating with your service's consumers using patterns
Managing user notifications
Logging application analytics and errors
Authentication using OAuth 2.0
Chapter 5: Data Management
Models provide the state and business logic
Implementing a CRUD data service
Caching data to reduce network traffic
Transforming data in the service
Chapter 6: Mashing in External Services
Storing events with Google Calendar
Using Google Tasks to build a brewing task list
Tying the Google Calendar and task list together
Chapter 7: Implementing the Business Logic
Encapsulating business logic in models
Encapsulating business logic in services
Models or services, which one to use?
Controlling a view flow with a state machine
Validating complex data with a rules engine
Chapter 8: Putting It All Together
Wiring in authentication
Displaying notifications and errors
Controlling the application flow
Displaying data from external services
Building and calculating the recipe
Messaging is the heart of the application

What You Will Learn

  • Write Jasmine scenarios to test your AngularJS services
  • Implement common functionality that can be leveraged by the controllers, directives, and other services in your application
  • Build services that create, retrieve, update, and delete your application's data on external servers
  • Incorporate third-party JavaScript libraries into your AngularJS application
  • Move business logic to the client side to build a new class of serverless applications
  • Optimize your AngularJS application for maximum performance

In Detail

This book provides you with the skills and best practices needed to create AngularJS services. It starts with the fundamentals of what services are and their role in a typical AngularJS application. You will walk through the development of a real-world application using services across the various application layers and then move on to create services that provide cross-cutting concerns such as messaging, logging, and authentication.

Next, the book covers services that provide data access showing you how to interact with external cloud-based data services and how to cache data on the client to reduce network latency. The book then shows you how to write services that leverage other cloud-based services to create mashups and include functionality in your application without writing a lot of code.

You will also learn how to create business logic objects, rules engines, and finite state machines, which can be used to provide business logic for your application.


Read More