Dependency Injection with AngularJS
Copyright 2013 Packt Publishing
All rights reserved. No part of this book may be reproduced, stored in a retrieval system, or transmitted in any form or by any means, without the prior written permission of the publisher, except in the case of brief quotations embedded in critical articles or reviews.
Every effort has been made in the preparation of this book to ensure the accuracy of the information presented. However, the information contained in this book is sold without warranty, either express or implied. Neither the author, nor Packt Publishing, and its dealers and distributors will be held liable for any damages caused or alleged to be caused directly or indirectly by this book.
Packt Publishing has endeavored to provide trademark information about all of the companies and products mentioned in this book by the appropriate use of capitals. However, Packt Publishing cannot guarantee the accuracy of this information.
First published: December 2013
Production Reference: 1111213
Published by Packt Publishing Ltd.
Livery Place
35 Livery Street
Birmingham B3 2PB, UK.
ISBN 978-1-78216-656-6
www.packtpub.com
Cover Image by Abhishek Pandey (<>
)
Credits
Author
Alex Knol
Reviewers
Iwan van Staveren
Ruoyu Sun
Acquisition Editor
James Jones
Commissioning Editor
Neil Alexander
Technical Editors
Sharvari H. Baet
Dennis John
Copy Editors
Alisha Aranha
Roshni Banerjee
Tanvi Gaitonde
Gladson Monteiro
Shambhavi Pai
Adithi Shetty
Project Coordinator
Sherin Padayatty
Proofreader
Simran Bhogal
Indexer
Rekha Nair
Production Coordinator
Kyle Albuquerque
Cover Work
Kyle Albuquerque
About the Author
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 kaizegine.com. 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 Risingtool.com.
I'd like to thank the AngularJS team for continuously improving the framework and documentation; my employer, Risingtool.com, for allowing me to work on this book, partly on their time. This book also took time away from my family time, for which I'd like to thank my wife and children.
About the Reviewers
Iwan van Staveren is a software architect. He has over 14 years of experience in developing all kinds of web applications. He loves working with the Symfony2 and AngularJs frameworks. He is owner of the privately-owned E-one Software.
Ruoyu Sun is a designer and developer living in Hong Kong. He is passionate about programming and has been contributing to several open source projects. He has founded several tech startups, using a variety of technologies, before going into the IT industry. He is the author of the book Designing for XOOPS , O'Reilly Media , July 2011 .
I would like to thank all my friends and family who have always supported me.
www.PacktPub.com
Support files, eBooks, discount offers, and more
You might want to visit www.PacktPub.com for support files and downloads related to your book.
Did you know that Packt offers eBook versions of every book published, with PDF and ePub files available? You can upgrade to the eBook version at > for more details.
At www.PacktPub.com, you can also read a collection of free technical articles, sign up for a range of free newsletters and receive exclusive discounts and offers on Packt books and eBooks.
http://PacktLib.PacktPub.com
Do you need instant solutions to your IT questions? PacktLib is Packt's online digital book library. Here, you can access, read and search across Packt's entire library of books.
Why subscribe?
- Fully searchable across every book published by Packt
- Copy and paste, print, and bookmark content
- On-demand and accessible via web browsers
Free access for Packt account holders
If you have an account with Packt at www.PacktPub.com, you can use this to access PacktLib today and view nine entirely free books. Simply use your login credentials for immediate access.
Preface
Dependency Injection is a term often used in the world of object-oriented software design. AngularJS depends on it at its core. This book teaches you why and how to use Dependency Injection with AngularJS.
What this book covers
, Learning to Fly , will take you through the basics of an Angular application. This chapter prepares a sample app that will be used throughout the examples in the book.
, Better Code , takes you from bad coding practices to maintainable and testable software using Dependency Injection. It also shows you the theory of Dependency Injection and some of its positive effects.
, The Magic , is a technical explanation of how Dependency Injection can be used with AngularJS and the caveats to watch out for.
, Testing , is a chapter that will show you the advantages that Dependency Injection brings when testing your application. Integration testing and unit testing are covered. The set up and use of recommended AngularJS testing frameworks are covered as well.
, Large Applications , will show you ways to implement the theory and techniques used in large applications. The result will be less code and better maintainability.
What you need for this book
To play along with the examples in this book, you just need a working installation of NodeJS and a text editor. To view the output, a web browser is required.
Who this book is for
If you are a developer or software engineer, this book is ideal for you. You should have a basic understanding of JavaScript and web development.
Conventions
In this book, you will find a number of styles of text that distinguish between different kinds of information. Here are some examples of these styles, and an explanation of their meaning.
Code words in text, database table names, folder names, filenames, file extensions, pathnames, dummy URLs, user input, and Twitter handles are shown as follows: "Earlier, you saw how to use the ng-app
attribute to bootstrap the application."
A block of code is set as follows:
When we wish to draw your attention to a particular part of a code block, the relevant lines or items are set in bold: