Dependency Injection with AngularJS

Dependency Injection with AngularJS

Language: English

Pages: 78

ISBN: 1782166564

Format: PDF / Kindle (mobi) / ePub


If you want to start using AngularJS for real, this is the book you need. Its down-to-earth practical approach will quickly teach you all you need to know about dependency injection utilizing this versatile framework.

Overview

  • Understand the concept of dependency injection
  • Isolate units of code during testing JavaScript using Jasmine
  • Create reusable components in AngularJS

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.

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

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

Approach

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

Who this book is written 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.

Building Web Apps with WordPress

WordPress Bible (2nd Edition)

Developing Web Apps with Haskell and Yesod: Safety-Driven Web Development (2nd Edition)

Google AdWords For Dummies

Enterprise Web Development: Building HTML5 Applications: From Desktop to Mobile

 

 

 

 

 

 

 

 

 

 

 

things for us. It saves us from having to write a bunch of boilerplate code. Dependency Injection is baked into AngularJS and heavily used throughout. Another feature is a built-in subset of a jQuery functionality called jQLite. It contains all the necessary functions to make AngularJS run without jQuery and has the exact same interface. If jQuery is available in your application, it will be used instead. Angular also takes the burden of bootstrapping your application, which will be covered later

negative testing. We are now expecting things to be there, but it gets more interesting when we start testing for edge negatives. A scenario that describes typing a name in an e-mail input field could look like the following: // pseudo code describe "login form" it "should require an email address" element('#submit').click() expect(input#email('name')).to_raise(validation_exception) … This will test if an exception was raised when the input was filled with some unacceptable value. This test

end-to-end tests from the /test/e2e/ folder and execute them inside a Firefox browser. The tests can be started by simply executing /scripts/test-e2e.sh. The difference is that this time as well the application server has to be started along with the Selenium server. Starting the server is, the same as before, to be able to access the application in a browser: node scripts/web-server.js Installing Selenium is as easy as downloading the appropriate JAR files from

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 (abhishek.pandey1210@gmail.com) www.it-ebooks.info Credits Author Project Coordinator Alex Knol

using to get the job done. Packt books are more specific and less general than the IT books you have seen in the past. Our unique business model allows us to bring you more focused information, giving you more of what you need to know, and less of what you don't. Packt is a modern, yet unique publishing company, which focuses on producing quality, cutting-edge books for communities of developers, administrators, and newbies alike. For more information, please visit our website: www.packtpub.com.

Download sample

Download