a blog for those who code

Sunday, 16 June 2019

How to fix NullInjectorError: No provider for TagServiceProxy


In this post we will be looking at fixing NullInjectorError: No provider for TagServiceProxy! error in Asp.Net Boilerplate using Angular 6. This happens when you create a new AppService in Appication project and when you try to use it in the component.


For example, I have created a TagAppService implementing the below interface like below

namespace LetsDisc.Tags
{
  public interface ITagAppService : IApplicationService
  {
    Task<PagedResultDto<TagDto>> GetTags(PagedResultRequestDto input);
  }
}

And when I tried to use it in the Angular Component as below it threw NullInjectorError: No provider for TagServiceProxy! error

@Component({
  selector: 'app-tags',
  templateUrl: './tags.component.html',
  styleUrls: ['./tags.component.css']
})

export class TagsComponent extends PagedListingComponentBase<TagDto> {
  tags: TagDto[] = [];
  constructor(injector: Injector, private _tagService: TagServiceProxy) {
    super(injector);
  }
}

To fix this I have to add a provider for the TagServiceProxy in service-proxy.module.ts as shown below

import { NgModule } from '@angular/core';
import { HTTP_INTERCEPTORS } from '@angular/common/http';
import { AbpHttpInterceptor } from '@abp/abpHttpInterceptor';
import * as ApiServiceProxies from './service-proxies';

@NgModule({
  providers: [
      ...,  
    ApiServiceProxies.TagServiceProxy,  
    { provide: HTTP_INTERCEPTORS, useClass: AbpHttpInterceptor, multi: true }
  ]
})

export class ServiceProxyModule { }

Thus the error is gone once refreshed the application

No comments:

Post a comment