Reputation: 66
I have searched a lot about this error and nothing was useful, this kind of error usually angular tells you what is the object that lacks a provider, however this time it's giving that StaticInjectorError(AppModule)[[object Object]], so I couldn't figure it out.
In my app, I have separate modules:
each of them has a routing module Indeed, I am using lazyloading to route across modules. The account-routing-module contains:
const routes: Routes = [
{
path: '',
component: AccountsComponent,
canActivate: [AuthGuardService],
resolve: {
data:{
AccountsResolver
}
}
}
];
@NgModule({
imports: [RouterModule.forChild(routes)],
exports: [RouterModule],
providers: [
AccountsResolver
]
})
export class AccountsRoutingModule {
}
when I access the accountscomponent, the following error appears:
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
but when I comment out the AccountsResolver in the resolve, the component loads normally without any error. I don't know if the error is because of the AccountsResolver which implements Resolve, or because of something else. Any idea will be appreciated. Thank you.
Upvotes: 3
Views: 3105
Reputation: 612
I know the answer is a bit late but if anyone else runs in to this problem: I had the exact same error message and it was due to malformed resolve In my case I wrote
const routes: Routes = [
{
path: '',
component: SomeComponent,
resolve: SomeResolveService
}
];
But it should be like:
const routes: Routes = [
{
path: '',
component: SomeComponent,
resolve: {someProperty: SomeResolveService}
}
];
So I guess removing the extra object should fix the problem:
resolve: {
data:AccountsResolver
}
Upvotes: 12