I have HeroMockService that will return mocked data and HeroService that will call back end service to retrieve heroes from database.
Assum
A lot of these answers are correct but will fail tree shaking. The mock services will be included as part of the final application which is usually not what is desired. In addition, it isn't easy to switch in and out of mock mode.
I have created a working example which solves these problems: https://github.com/westonpace/angular-example-mock-services
useClass/provide fields to provide the interface/abstract class)environment.*.ts files load either the RealModule or the MockModuleangular.json file used by angular-cli to create a new build target mock which builds with the mock environment file which injects the MockModule. Create a new serve configuration which serves up the mock build so you can do ng serve -c mock. Change the default protractor configuration so that it uses the mocked serve target so ng e2e will run against your mock services.