Understanding providers
A provider tells Angular 2 how to create an instance of a service while injecting it. A provider is set using the providers
or viewProviders
properties of a component.
Let's look at an example of how to create providers. Place this code above the App
component's code:
var Service1 = ng.core.Class({ constructor: function() { }, getValue: function() { return "xyz" } }); var Service2 = ng.core.Class({ constructor: function() { }, getValue: function() { return "def" } }); var Service3 = ng.core.Class({ constructor: function() { }, getValue: function() { return "mno" } }); var Service4 = ng.core.Class({ constructor: [Service2, Service3, function(s2, s3) { console.log(s2); console.log(s3); }], getValue: function() { return "abc" } }); var ServiceTest1 = ng.core.Component({ selector: "st1", viewProviders: [ ng.core.provide(Service1, {useClass: Service4}), ng.core.provide(Service2, {useValue: "def"}), ...