-
Book Overview & Buying
-
Table Of Contents
Angular Cookbook
By :
Optional dependencies in Angular are really powerful when you use or configure a dependency that may or may not exist or that has been provided within an Angular application. In this recipe, we'll learn how to use the @Optional decorator to configure optional dependencies in our components/services. We'll work with LoggerService and ensure our components do not break if it has not already been provided.
The project for this recipe resides in chapter03/start_here/ng-optional-dependencies. Perform the following steps:
npm install to install the dependencies of the project. ng serve -o. This should open the app in a new browser tab. You should see something similar to the following screenshot:
Figure 3.2 – The ng-optional-dependencies app running on http://localhost:4200
Now that we have the app running...