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" ...

Get JavaScript: Moving to ES2015 now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.