Search code examples
javascriptangularecmascript-5

Angular 2 hierarchical Providers in ES5


I'm getting started using Angular 2 using ES5, and I've hit a brick wall when setting up my providers. In essence, I want to make a provider depend on HTTP. Here's how i have it set up:

var Provider = ng.core.Class({
    constructor: [ng.http.Http, function(http) {
       // some code here that uses HTTP
    }]
});

var Component = ng.core.Component({
    providers: [Provider, ng.http.HTTP_PROVIDERS]
}).Class({
    constructor: [Provider, function(provider) {
        // some code here that uses my Provider
    }]
});

I keep getting the following error: No provider for t! (e -> t)

I've omitted the rest of the boilerplate code because this is where I'm stuck. Do I have a misunderstanding about how I'm injecting my dependencies? How do I set up hierarchical dependencies in Angular 2 in ES5?


Solution

  • I figured it out. In the actual code I was using, I ended up having something like this: providers: [[Provider, ng.http,HttpProviders]] which shouldn't have been a nested array