Dependency Injection with AngularJS

Dependency Injection with AngularJS
eBook: $17.99
Formats: PDF, PacktLib, ePub and Mobi formats
save 15%!
Print + free eBook + free PacktLib access to the book: $47.98    Print cover: $29.99
save 6%!
Free Shipping!
UK, US, Europe and selected countries in Asia.
Also available on:
Table of Contents
Sample Chapters
  • Understand the concept of dependency injection
  • Isolate units of code during testing JavaScript using Jasmine
  • Create reusable components in AngularJS

Book Details

Language : English
Paperback : 78 pages [ 235mm x 191mm ]
Release Date : December 2013
ISBN : 1782166564
ISBN 13 : 9781782166566
Author(s) : Alex Knol
Topics and Technologies : All Books, Application Development, Open Source

Table of Contents

Chapter 1: Learning to Fly
Chapter 2: Better Code
Chapter 3: The Magic
Chapter 4: Testing
Chapter 5: Large Applications
  • Chapter 1: Learning to Fly
    • Let's get going
    • Adding a controller
    • What about routes?
    • Showing a list
    • Adding a filter
    • Chart directives
      • Using services
    • Summary
  • Chapter 2: Better Code
    • Wiring up the backend
    • Duplicating code
    • Angular service to the rescue
    • The theory behind Dependency Injection
    • Summary
  • Chapter 4: Testing
    • Test automation
    • Test your code, not the framework
    • Testing the parts
    • The Karma test runner
    • End-to-end testing
      • Setting up the Protractor
    • Summary
  • Chapter 5: Large Applications
    • Organizing your application
      • Going a bit larger
    • Organizing using dynamic teams
      • Using modules
      • Organizing using directives
    • Nesting controllers
    • More powerful nesting
    • Application communication
      • Events
      • Let the model speak
    • Summary

Alex Knol

Alex Knol is a lifelong tech geek with a passion for automation. After spending some years away from software development, around the beginning of this century, he took up PHP development based on his early experiences with C and Pascal. Surprisingly, he has never really used web tools, but applications instead, to make websites, such as the platform that's driving Having built various applications using web technologies and frameworks, such as Symfony, he discovered AngularJS at the beginning of 2008, while searching for a way to structure frontend application code and make development easy. He used AngularJS, among other technologies, for a job-matching project in the Netherlands and, more recently, for an online website designer named

Submit Errata

Please let us know if you have found any errors not listed on this list by completing our errata submission form. Our editors will check them and add them to this list. Thank you.


- 3 submitted: last submission 19 May 2014

Please igore the code download tip present on pages 3 and 15 of the book. This book doesn't have a separate code bundle. Please follow the steps and code given in the book.

Errata Type: Code  Page 18


The second line of code on page 18 has an error. The correct one is as follows (the change has been highlighted - Missing quotes):

<script type="text/javascriptsrc=""></script>

The code snippets in the book uses "Celcius". The correct spelling is "Celsius". But please make sure that if you want to use the correct spelling, make changes across all instances.

Sample chapters

You can view our sample chapters and prefaces of this title on PacktLib or download sample chapters in PDF format.

Frequently bought together

Dependency Injection with AngularJS +    AngularJS Directives =
50% Off
the second eBook
Price for both: $26.00

Buy both these recommended eBooks together and get 50% off the cheapest eBook.

What you will learn from this book

  • Create reusable components propelled by the independence of components from each other
  • Run tests on real browsers using the Karma test runner
  • Set up Jasmine BDD testing
  • Set up and install AngularJS
  • Change coupled code to loosely coupled injected dependencies
  • Create integration tests using Protractor
  • Organize large applications using dependency injection

In Detail

Dependency injection facilitates better testing by allowing us to mock dependencies in testing environments so that we only test one thing at a time. It also enables us to write more maintainable code by decoupling our objects from their implementations. The motivation for using it in AngularJS is to make it easier to transparently load mocked objects in tests.

This book is a practical manual to get you started on dependency injection. It will also take you along the road to creating testable and reusable code. Ensuring productivity and stability are the two most important things that you will learn.

"Dependency Injection with AngularJS" will introduce you to AngularJS using a simple sample project. By portraying different ways of developing code modules, it will show you the advantages of dependency injection. This will lead to the ability to create reusable components that can easily be tested.

The book contains a section that will show you how to make a chart component to display historical data. A short chapter will explain some of the theory and the reasons behind dependency injection. You will be introduced to Jasmine, a JavaScript behavior-driven development testing framework. You will learn how to test your code in real browsers using Karma, the lightning fast AngularJS test runner. Lastly the book will show you how to build reusable components you can stack on top of each other.

You will learn everything you need to know how to use dependency injection with AngularJS.


This book is a practical, hands-on approach to using dependency injection and implementing test-driven development using AngularJS.

Who this book is for

Dependency Injection with AngularJS is aimed at developers who are aware of AngularJS but need to get started with using it in real life applications. Also, developers who want to get into test-driven development with AngularJS can use this book as practical guide. Even if you know about dependency injection, it can serve as a good reference on how it is used within AngularJS. Readers are expected to have some experience with JavaScript.

Code Download and Errata
Packt Anytime, Anywhere
Register Books
Print Upgrades
eBook Downloads
Video Support
Contact Us
Awards Voting Nominations Previous Winners
Judges Open Source CMS Hall Of Fame CMS Most Promising Open Source Project Open Source E-Commerce Applications Open Source JavaScript Library Open Source Graphics Software
Open Source CMS Hall Of Fame CMS Most Promising Open Source Project Open Source E-Commerce Applications Open Source JavaScript Library Open Source Graphics Software