a blog for those who code

Friday 26 October 2018

How I solved NullInjectorError: No provider for Error in AspNetBoilerplate

I started working on AspNetBoilerplate with AngularJS frontend and I was getting error as ERROR Error: Uncaught (in promise): Error: StaticInjectorError(RootModule)[QuestionsComponent -> QuestionServiceProxy]:
  StaticInjectorError(Platform: core)[QuestionsComponent -> QuestionServiceProxy]:
    NullInjectorError: No provider for QuestionServiceProxy!.


I searched over the internet about possible fixes and everyone was saying that you need to import the component which was already imported as

import { QuestionServiceProxy, QuestionDto, PagedResultDtoOfQuestionDto } from '@shared/service-proxies/service-proxies';

The service-proxies also had QuestionServiceProxy which made it ver confusing that why I was getting the error. What I missed is the service.proxy.module.ts where I need to also include it using @NgModule as shown below :

@NgModule({
 providers: [
  ApiServiceProxies.RoleServiceProxy,
  ApiServiceProxies.SessionServiceProxy,
  ApiServiceProxies.TenantServiceProxy,
  ApiServiceProxies.UserServiceProxy,
  ApiServiceProxies.QuestionServiceProxy,
  ApiServiceProxies.TokenAuthServiceProxy,
  ApiServiceProxies.AccountServiceProxy,
  ApiServiceProxies.ConfigurationServiceProxy,
  { provide: HTTP_INTERCEPTORS, useClass: AbpHttpInterceptor, multi: true }
  ]
})
export class ServiceProxyModule { }

Thus it fixed the issue. Please like and share the CodingDefined.com blog if you find it useful and helpful.

No comments:

Post a Comment