-
Book Overview & Buying
-
Table Of Contents
Angular Cookbook - Second Edition
By :
In this recipe, you'll learn how to provide two different services to the app using Aliased class providers. This is extremely helpful in complex applications where you need to narrow down the implementation of the service/class for some components/modules. That is providing different classes against the same DI token to have a polymorphic behavior. Additionally, aliasing is used in component/service unit tests to mock the dependent service's actual implementation so that we don't rely on it.
The app that we are going to work with resides in start/apps/chapter03/ng-aliased-class-providers inside the cloned repository:
npm run serve ng-aliased-class-providers to serve the projectThis should open the app in a new browser tab and you should see the app as shown in Figure 3.11