gpt4 book ai didi

javascript - ES5 中的 Angular 2 分层提供程序

转载 作者:太空狗 更新时间:2023-10-29 18:00:05 24 4
gpt4 key购买 nike

我开始使用使用 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
}]
});

我不断收到以下错误:t 没有提供者! (e -> t)

我省略了其余的样板代码,因为这是我被卡住的地方。我对如何注入(inject)依赖项有误解吗?如何在 ES5 中的 Angular 2 中设置层次依赖关系?

最佳答案

我想通了。在我使用的实际代码中,我最终得到了这样的东西:providers: [[Provider, ng.http,HttpProviders]] 不应该是嵌套数组

关于javascript - ES5 中的 Angular 2 分层提供程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35906043/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com