Angular Essentials by Infragistics

Angular Essentials by Infragistics

Author:Infragistics
Language: eng
Format: epub
Publisher: Infragistics
Published: 2017-03-23T13:26:44+00:00


Listing 27.9: providers using useValue

Using Factory Functions for Services

Factory pattern is commonly used to abstract the logic of creating an object depending upon certain values in the application, and the environment. Angular 2 supports this pattern through the useFactory property in the providers option. A function creating an object of the class can be registered as the factory function for the service. Listing 27.10 creates a simple factory function for DataService, like any other class or object, the factory function can be created anywhere and imported into the file creating module:



Download



Copyright Disclaimer:
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.