How to mock providers in Angular

Published: Sun May 10 2015

Providers in Angular serve as a way to create independent components that can be injected into other components. There are several different types of providers; service, factory, value, constant and provider, but the idea is very similar between all of them.

In this post I will demonstrate how to mock the different types through Angular dependency injection.

Below are simple examples of the different provider types. The actual implementation of the getCustomerById method is omitted for brevity.