O'Reilly logo

AngularJS Services by Jim Lavin

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Designing for testability

AngularJS was built with testability in mind and that is evident in how dependency injection plays a major role in the various constructor methods that are part of the module component.

Law of Demeter

Dependency injection allows you to write code that is loosely coupled to the services it's dependent on. This allows you to write code that follows the Law of Demeter, which is a best practice when writing testable code. In its general form, the Law of Demeter says that each unit of code should have only limited knowledge about other units of code.

In other words, don't call chained objects in your methods. Instead, pass in the objects you need to interact with. If you call a chained object in your methods, you increase the ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required