gpt4 book ai didi

Angular6:错误:StaticInjectorError(AppModule)[[对象对象]]

转载 作者:行者123 更新时间:2023-12-02 19:18:09 25 4
gpt4 key购买 nike

我已经搜索了很多有关此错误的信息,但没有任何有用的信息,这种错误通常有角度地告诉您缺少提供程序的对象是什么,但是这次它给出了 StaticInjectorError(AppModule)[[object Object ]],所以我无法弄清楚。

在我的应用程序中,我有单独的模块:

  1. 应用程序模块
  2. 费用模块
  3. 账户模块

他们每个人都有一个路由模块事实上,我正在使用延迟加载来跨模块路由。帐户路由模块包含:

const routes: Routes = [
{
path: '',
component: AccountsComponent,
canActivate: [AuthGuardService],
resolve: {
data:{
AccountsResolver
}
}
}
];

@NgModule({
imports: [RouterModule.forChild(routes)],
exports: [RouterModule],
providers: [
AccountsResolver
]

})
export class AccountsRoutingModule {
}

当我访问accounts组件时,出现以下错误:

ERROR Error: Uncaught (in promise): Error: StaticInjectorError(AppModule)[[object Object]]: 
StaticInjectorError(Platform: core)[[object Object]]:
NullInjectorError: No provider for [object Object]!
Error: StaticInjectorError(AppModule)[[object Object]]:
StaticInjectorError(Platform: core)[[object Object]]:
NullInjectorError: No provider for [object Object]!
at NullInjector.push../node_modules/@angular/core/fesm5/core.js.NullInjector.get (vendor.js:53611)
at resolveToken (vendor.js:53850)
at tryResolveToken (vendor.js:53795)
at StaticInjector.push../node_modules/@angular/core/fesm5/core.js.StaticInjector.get (vendor.js:53690)
at resolveToken (vendor.js:53850)
at tryResolveToken (vendor.js:53795)
at StaticInjector.push../node_modules/@angular/core/fesm5/core.js.StaticInjector.get (vendor.js:53690)
at resolveNgModuleDep (vendor.js:60745)
at NgModuleRef_.push../node_modules/@angular/core/fesm5/core.js.NgModuleRef_.get (vendor.js:61433)
at resolveNgModuleDep (vendor.js:60745)
at NullInjector.push../node_modules/@angular/core/fesm5/core.js.NullInjector.get (vendor.js:53611)
at resolveToken (vendor.js:53850)
at tryResolveToken (vendor.js:53795)
at StaticInjector.push../node_modules/@angular/core/fesm5/core.js.StaticInjector.get (vendor.js:53690)
at resolveToken (vendor.js:53850)
at tryResolveToken (vendor.js:53795)
at StaticInjector.push../node_modules/@angular/core/fesm5/core.js.StaticInjector.get (vendor.js:53690)
at resolveNgModuleDep (vendor.js:60745)
at NgModuleRef_.push../node_modules/@angular/core/fesm5/core.js.NgModuleRef_.get (vendor.js:61433)
at resolveNgModuleDep (vendor.js:60745)
at resolvePromise (polyfills.js:3136)
at resolvePromise (polyfills.js:3093)
at polyfills.js:3195
at ZoneDelegate.push../node_modules/zone.js/dist/zone.js.ZoneDelegate.invokeTask (polyfills.js:2743)
at Object.onInvokeTask (vendor.js:56325)
at ZoneDelegate.push../node_modules/zone.js/dist/zone.js.ZoneDelegate.invokeTask (polyfills.js:2742)
at Zone.push../node_modules/zone.js/dist/zone.js.Zone.runTask (polyfills.js:2510)
at drainMicroTaskQueue (polyfills.js:2917)
defaultErrorLogger @ vendor.js:54201

但是当我在解析中注释掉 AccountsResolver 时,该组件正常加载,没有任何错误。我不知道该错误是由于实现 Resolve 的 AccountsResolver 还是由于其他原因。任何想法将不胜感激。谢谢。

最佳答案

我知道答案有点晚了,但如果其他人遇到这个问题:我收到了完全相同的错误消息,这是由于解析格式错误造成的就我而言,我写了

const routes: Routes = [
{
path: '',
component: SomeComponent,
resolve: SomeResolveService
}
];

但它应该是这样的:

const routes: Routes = [
{
path: '',
component: SomeComponent,
resolve: {someProperty: SomeResolveService}
}
];

所以我想删除额外的对象应该可以解决问题:

resolve: {
data:AccountsResolver
}

关于Angular6:错误:StaticInjectorError(AppModule)[[对象对象]],我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51261216/

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