我开始使用ES5开始使用Angular 2,并且在设置我的提供程序时遇到了困难.本质上,我想让提供者依赖于HTTP.这是我如何设置它:
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
}]
});
我一直收到以下错误:没有提供商! (e – > t)
我省略了其余的样板代码,因为这是我被困住的地方.我是否对如何注入依赖关系有误解?如何在ES5中的Angular 2中设置层次依赖?
最佳答案 我想到了.在我使用的实际代码中,我最终得到了类似的东西:provider:[[Provider,ng.http,HttpProviders]]这不应该是嵌套数组